I have a collection model. I succesfully created a _collection.html.erb that i call with <%= render @collections%> in my application layout.
My problem is that in ALL my controlers method I must add @collections = Collection.all
I found it very very ugly,it will make my collection scope a pain to change, and I’m sure that I am missing a rails magic something that would be way nicer.
Is there a way to have a part of the layout generated by model data without having a identical piece of code in AAAALLLLLL the controllers?
Notice that your controllers all inherit from
ApplicationController. Use this to your advantage. Add abefore_filtertoApplicationControllerthat loads your collections.