today I wanted to use some variables in my shared/menu partial. I know that I should put somewhere in application_controller some helper method (or something like that) but it doesn’t work for me. Here is my temporary solution (shared/_menu.html.haml):
- @pagecontents = Pagecontent.all
- @pagecontents.each do |pc|
%ul
%li
= link_to pc.title, pc
I don’t want to define @pagecontents variable directly in my view! :/ My problem is to add @pagecontent variable somewhere to application_controller file but when I tried e.g:
def pagecontentforpartial
@pagecontents = Pagecontent.all
end
and then tried to access this variable in my partial view I got an error that this method is nil (but there is already a lot of records!) Someone can explain me how solve this problem?
You can pass object to your partial directly using
rendermethodIt’s your
shared/_menu.html.haml:And when you need to show it, you can use this method in your view
@pagecontentsis from controller, of course