Skip to main content
Ask A Question
Notifications
You’re not receiving notifications from this thread.
Subscribe

How do I implement Facades Pattern on a already advanced Ruby on Rails project?

General • Asked by Andres Max

A few days ago read the four rules for developers and the Facade Pattern got my attention, however, find it somehow complicated to implement due to lack of good tutorials or the ones I've read implement it in very different ways.

Any help would be appreciated. Thanks.


The Facade Pattern is a pretty simple one. In Rails the guideline is usually to only have like one instance variable that your controller sets. Reality is that often times you need several variables to render the page, so they create a little Ruby object that's nothing special like their example of Dashboard. It just has a few methods so you interact with the Dashboard instead of several different instance variables in the view.

This pattern doesn't really improve your code all that much. It more hides the complexity behind a facade (hence the name) but it significantly improves the controller code.

You can simply create an app/facades folder for this and as long as the directory loads (you may need to add it to the Rails config, can't remember), then all you'll have to do is create some basic Ruby classes that load the correct records and you're all set.


Since this pattern is simply and helpful but "doesn't really improve your code...", what would you recommend instead?

Thanks a lot!


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 30,005+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.