3: <%= e.submit ‘search’, :controller => ‘employees’, :action =>
‘search1’ %>
4: <% end %>
in my search action i dint provide anything like
def search
end
if i use <%= form_for(:employee) do |e| %>
it shows no error but the data is moving in to my “show” action
I got nothing in my action search and linked the search button to
search1 action, which contains the find function is that a problem?
Yes. Here is the order of what happens:
The browser sends a request that is routed to the action that
corresponds to your view with the form.
The action executes and the view containing your form is processed by
rails and sent to the browser.
All variables in your app and their values are destroyed.
The user fills out the form and clicks the submit button, which sends
the request to your search1 action, causing the code in search1 to
execute.
So any code in the search1 action executes long after rails processes
the view containing your form. In your view, you referenced the @employee variable, so that
view’s action has to assign a value to @employee.
the search method doesn’t declare any instance variable but in the view
template,
you want to use @employee. form_for expects @employee to be declared so
that form_for can form the url and the input field names. so the
solution
to your
problem is to just declare an @employee in the search action.