html - NoMethodError in StaticPages#home when attempting to list database query -


ruby noob here, created search form , trying query db , display results. getting nomethoderror in staticpages#home along with.... /home/action/projects/codoncodertest5/app/views/static_pages/home.html.erb line #4 raised:

undefined method `each' nil:nilclass

where going wrong?

layouts/staticpages/home

<h1>staticpages#home</h1> <% @data_bases.each |list| %>      <div class="list">          <h1 class="list-mrnacodon"><%= link_to list.mrnacodon %></h1>      </div> <% end %> 

controller

class databasecontroller < applicationcontroller    def new   end    def index      if params[:search]          @data_bases = match.search(params[:search]).order("created_at desc")      else          @data_bases = match.order("created_at desc")      end   end end 

the error means @data_bases in view evaluating nil. makes sense, since way view staticpages#home have access variable if set in corresponding controller action (i.e. home method on staticpagescontroller). looks you're setting variable on databasecontroller.

class staticpagescontroller < applicationcontroller    ...    def home     if params[:search]       @data_bases = match.search(params[:search]).order("created_at desc")     else       @data_bases = match.order("created_at desc")     end   end    ...  end 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -