# Local variables passed to a view

**URL:** <https://www.ruby-forum.com/t/local-variables-passed-to-a-view/159777>\
**Category:** Rails\
**Created:** [February 8, 2009, 5:41pm UTC](https://www.ruby-forum.com/t/local-variables-passed-to-a-view/159777 "2009-02-08T17:41:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ac91a4/32.png) [@jim](https://www.ruby-forum.com/u/jim)\
**Post date:** [February 8, 2009, 5:41pm UTC](https://www.ruby-forum.com/t/local-variables-passed-to-a-view/159777/1 "2009-02-08T17:41:34Z")

</div>

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.

\<%= 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 ?
