I am trying to generate a search form on my home#index.
However, when I do <%= simple_form_for @search do |f| %> in the view of Home#index, I get this error:
NoMethodError at /
Message undefined method `model_name' for NilClass:Class
Even though, in my Home#index in my controller, I have:
def index
render :layout => 'home'
@users = User.all
@search = Search.new
end
How do I get access to my search object from any view in my app? Btw, I have a Search model – if it wasn’t obvious from the call in my Home#index.
Thoughts?
Thanks.
if this view is shared across all your pages, you may skip declaring an instance variable and just call
Search.newright there on the form