Forum: Ruby on Rails Controller instance variables falling in and out of scope

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1c32688ea30399fc36eb61605f543aaf?d=identicon&s=25 Seth Rasmussen (Guest)
on 2006-03-22 08:05
(Received via mailing list)
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/
1c32688ea30399fc36eb61605f543aaf?d=identicon&s=25 Seth Rasmussen (Guest)
on 2006-03-22 08:06
(Received via mailing list)
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:
> <%= @post.inspect %> => nil
> much luck with IRC and my own debugging efforts. Any clues?
>
> --
> Seth Thomas Rasmussen
> http://sethrasmussen.com/
>


--
Seth Thomas Rasmussen
http://sethrasmussen.com/
1c32688ea30399fc36eb61605f543aaf?d=identicon&s=25 Seth Rasmussen (Guest)
on 2006-03-22 08:27
(Received via mailing list)
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:
> >   redirect_to :action => 'archive' unless @post
> > Ruby 1.8.2
>
> --
> Seth Thomas Rasmussen
> http://sethrasmussen.com/
>


--
Seth Thomas Rasmussen
http://sethrasmussen.com/
This topic is locked and can not be replied to.