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!
Join 30,005+ developers who get early access to new screencasts, articles, guides, updates, and more.