views:

103

answers:

3

Hi

so i have this code:

<% form_tag(:action => 'find') do%>
  Product name:
  <%= text_field("cars_", "name", :size => "30") %>
  <input type ="submit" value="Find"/>
<%end%>

upon pressing the button I want it to complete the method (def find) found in the controller but its requesting the html.erb file:

Template is missing

Missing template cars/find.erb in view path H:\Documents and Settings/owner/My Documents/NetBeansProjects/RailsApplication5/app/views

in the find def (found in controller)

def find
  @car = Car.new(params[:car_])
end
+3  A: 

What is the last line of your find method? Generally, if you don't specify the template to render in your controller method, Rails attempts to find a template with the same name as the method. That is why it is saying it can't find cars/find.erb. Without seeing the code in your find action, it is hard to give a better answer.

Chris Johnston
added to question!
Lily
Chirs is right. If you don't have a view for your find method then you need a redirect at the end of your method like `render :action => :show`
JosephL
+1  A: 

Your find method should be doing some searching, not initializing with the parameters. I recommend checking out something like thinking sphinx or searchlogic if you want to do searching.

Ryan Bigg
+1  A: 

I believe that your code is executing the find action. However, after it finds the car object, it needs to write that into a template that shows the results of your search. By convention, rails looks for a file called find.html.erb in the view folder for that controller. So, the error message you are seeing means that Rails has executed the line of code in your action and is now trying to generate some HTML to send back to the browser

If you create a simple file in the view folder for that controller with contents:

<%= @car.name %>

You should see the results.

However, your code is a bit confusing to me as I don't know why a find method would create a new Car object. I would expect something like this:

def find
  @car = Car.find_by_name(params[:name])
end

I would also expect that your form would be more like:

<% form_tag(:action => 'find') do%>
  Product name:
  <%= text_field_tag("name", :size => "30") %>
  <%= submit_tag "find" %>
<%end%>
MattMcKnight