title: Extra instance variable in controller is nil in view?
body: <p>I have been searching through Stack Overflow for a few hours now, but none of the related questions seem to apply to my issue.</p>
  
  <p>I am new to Rails, with this being my first real project, and I may be confusing the MVC setup a little. I am attempting to assign the @stars instance variable while in an action of the searches_controller.rb:</p>
  
  <pre><code>def create
    @search = Search.new(params[:search])
    tempstr = searchstr(@search)
    @stars = Star.where("tempstr", :limit =&gt; 100)
  end
  </code></pre>
  
  <p><code>@search</code> is created fine, being a complex search with varying parameters. <code>tempstr</code> is just a simple string container for the results of <code>searchstr(@search)</code>, which is a quick method for converting the search parameters into a MySql-relevant string (which seems to be easier than trying to use the .where helper normally, in this case). I'm sure I can just put <code>searchstr(@search)</code> directly into the .where, but I split them up for now so I can inspect the elements as they pass through.</p>
  
  <p>Anyways, the issue comes up when I try to call <code>@stars</code> in the show.html.erb view. Even with something as simple as this:</p>
  
  <pre><code>&lt;% @stars.each do |star| %&gt;
    &lt;%= display stuff %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>I get an error saying <code>'each' is not a method of nil:NilClass</code>. So, I changed it to the following to see if @stars was nil:</p>
  
  <pre><code>&lt;%= @stars.inspect %&gt;
  </code></pre>
  
  <p>Sure enough, <code>@stars</code> is <code>nil</code>. However, when I add this line to my controller to check <code>@stars</code> there:</p>
  
  <pre><code>return render @stars.each
  </code></pre>
  
  <p>I see that the variable is filled with the correct star objects from the Star.where(), just as I had intended. A quick .inspect shows the variable is not nil, when in the controller.</p>
  
  <p>So, I am unsure why the view is receiving it as nil if it has been defined in the controller just fine. I wouldn't be surprised if it was me misunderstanding how MVC works, though. The Star class was defined in the Star model, but maybe it is because I am trying to access it from the Searches controller, and thus it isn't initialized for the view?</p>
  
  <p>Should I be going about doing this some other way? I attempted to use a local variable (using <code>stars</code> instead of <code>@stars</code>), but then the view says "Undefined local variable or method 'stars'".</p>
  
  <p>Any help would be much appreciated, I have already wracked my brain for hours creating the complex search and parsing the star file data into the database, so I'm a bit burnt out. I can supply more information if requested, I'm not sure what else would be helpful in providing an answer.</p>