Forum: Ruby on Rails local variables passed to a view

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.
Fee0914d72a1a378fff49c5dd6f9d1ab?d=identicon&s=25 jim (Guest)
on 2009-02-08 17:41
(Received via mailing list)
experimenting, trying to understand local and instance vars and their
relationship to views

I have a controller with an index method.

it sets a local variable like this: (of course I could just make it an
instance variable here but ...)

search_results = Ticket.find(:all, :conditions => session
[:search_conditions]) if session[:search_conditions]


in the index view I say this to show the search results, "result" is
the name of the variable in the partial.

<div id="search_results">
<%= render :partial => 'search_results', :layout => false, :locals =>
{ :result => @search_results } %>
</div>

I'm not explicitly setting search_results as an instance variable
anywhere in the controller. But, just putting the @ in front of the
variable name in the index view seems to auto-magically convert local
variable search_results from the index controller method to an
instance variable usable in the index view.

Is that right? That's just the way it works in Rails 2.2 ?
This topic is locked and can not be replied to.