Hi folks, My controller sets an instance variable (@item) which somehow contains a different value in the layout than it does in the view. The controller (items_controller), has this action: def show @item = Item.find(params[:id]) @owner = User.find(@item.owner_id) return_to_main unless @item.status == $ITEM_STATUS_ACTIVE @other_items_from_owner = @owner.available_items_for_rent([@item]) end When I visit /items/show/123, it renders show.rhtml with all the correct info for item #123 inside the page content. Good so far. However, in my layout, I have: <title> <%= @item.name %> </title> And when I visit /items/show/123, the browser title contains the name of a different item! Now, if I rename the variable to something like @item_foo (in all places in the controller/layout/view), then it shows the CORRECT value in the title bar (and the page content). What could possibly cause the variable''s contents to be different in the layout than in the view? I''m not using any caching, by the way. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ryan Cush
2007-Jul-13 03:54 UTC
Re: instance variable has different value in layout vs. view
Never mind, mystery solved. I was thinking that the layout was rendered before the view, but obviously it''s the other way around. Turns out one of the partials in my view was inadvertently reassigning @item to something else. Now back to your regularly scheduled day || night. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---