Forum: Ruby on Rails local variables passed to a view

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
jim (Guest)
on 2009-02-08 18: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 } %>

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.