Seth Rasmussen
2006-Mar-22 07:04 UTC
[Rails] Controller instance variables falling in and out of scope
Very bizarre behavior has cropped up in a few spots. # the action for viewing a blog post def posts @post = BlogPost.find_by_slug(params[:id], :include => :commentary) # a breakpoint here shows @post and @post.commentary with appropriate data redirect_to :action => ''archive'' unless @post end # posts.rhtml <%= @post.inspect %> => nil <%= render :partial => ''post'', :object => @post %> => renders with correct data <%= @post.comments %> => NoMethodError <%= render_tree_of( @post.comments, ... ) %> => generates no errors, but within the partial reports @post.comments as nil WinXP Ruby 1.8.2 Edge Rails (behavior has existed over several iterations now) I''ve not run into anybody else with this problem, and have not had much luck with IRC and my own debugging efforts. Any clues? -- Seth Thomas Rasmussen http://sethrasmussen.com/
Seth Rasmussen
2006-Mar-22 07:06 UTC
[Rails] Re: Controller instance variables falling in and out of scope
I should probably add that BlogPost#comments is defined to return a mapped version of BlogPost#commentary. On 3/22/06, Seth Rasmussen <seths.mailing.lists@gmail.com> wrote:> Very bizarre behavior has cropped up in a few spots. > > # the action for viewing a blog post > def posts > @post = BlogPost.find_by_slug(params[:id], :include => :commentary) > # a breakpoint here shows @post and @post.commentary with appropriate data > redirect_to :action => ''archive'' unless @post > end > > # posts.rhtml > <%= @post.inspect %> => nil > <%= render :partial => ''post'', :object => @post %> => renders with correct data > <%= @post.comments %> => NoMethodError > <%= render_tree_of( @post.comments, ... ) %> => generates no errors, > but within the partial reports @post.comments as nil > > WinXP > Ruby 1.8.2 > Edge Rails (behavior has existed over several iterations now) > > I''ve not run into anybody else with this problem, and have not had > much luck with IRC and my own debugging efforts. Any clues? > > -- > Seth Thomas Rasmussen > http://sethrasmussen.com/ >-- Seth Thomas Rasmussen http://sethrasmussen.com/
Seth Rasmussen
2006-Mar-22 07:27 UTC
[Rails] Re: Controller instance variables falling in and out of scope
Turns out it was a filter in ApplicationController calling render_to_string... interesting behavior nonetheless. On 3/22/06, Seth Rasmussen <seths.mailing.lists@gmail.com> wrote:> I should probably add that BlogPost#comments is defined to return a > mapped version of BlogPost#commentary. > > On 3/22/06, Seth Rasmussen <seths.mailing.lists@gmail.com> wrote: > > Very bizarre behavior has cropped up in a few spots. > > > > # the action for viewing a blog post > > def posts > > @post = BlogPost.find_by_slug(params[:id], :include => :commentary) > > # a breakpoint here shows @post and @post.commentary with appropriate data > > redirect_to :action => ''archive'' unless @post > > end > > > > # posts.rhtml > > <%= @post.inspect %> => nil > > <%= render :partial => ''post'', :object => @post %> => renders with correct data > > <%= @post.comments %> => NoMethodError > > <%= render_tree_of( @post.comments, ... ) %> => generates no errors, > > but within the partial reports @post.comments as nil > > > > WinXP > > Ruby 1.8.2 > > Edge Rails (behavior has existed over several iterations now) > > > > I''ve not run into anybody else with this problem, and have not had > > much luck with IRC and my own debugging efforts. Any clues? > > > > -- > > Seth Thomas Rasmussen > > http://sethrasmussen.com/ > > > > > -- > Seth Thomas Rasmussen > http://sethrasmussen.com/ >-- Seth Thomas Rasmussen http://sethrasmussen.com/