Routes & Link_to

Hi,
I really don’t know if i am doing this correctly, so please tell me if
so.
I have a product model who has many ingredients.
So in my product form i’ve added a text_field to put the ingredient, and
create or find it on the “add” action.

Here is what i’ve done
View:
<% form_for @product do |f| %>
<%= f.error_messages %>

<%= f.label :name %>
<%= f.text_field :name %>

<%= f.label :prod_type %>
<%= f.text_field :prod_type %>

<%= f.label :min_visit %>
<%= f.text_field :min_visit %>

<%= f.label :max_visit %>
<%= f.text_field :max_visit %>

<%= f.label :price %>
<%= f.text_field :price %>

<%= f.label :visible %>
<%= f.text_field :visible %>

<%= f.label :ingredient_name %> <%= text_field_with_auto_complete :product, :ingredient_name,{}, {:url => formatted_ingredients_path(:js), :method => :get, :with => "'search=' + element.value"} %> <%=link_to "Add",add_ingredient_product_path %> <%= render :partial => "ingredient", :collection => @product.ingredients %>

<%= f.submit "Submit" %>

<% end %>

Product controller:
def add_ingredient
@product = Product.find(params[:id])
@product.ingredients <<
Ingredient.find_or_create_by_name(params[:search])
@product.update_attributes(params[:product])
end

Route:
map.resources :products,
:member => {:add_ingredient => :put }

Ok, first question I am doing this correcty?
And when I clic “add” to add the ingredient to the current product I
have this message: "Unknown action

No action responded to 396. Actions: add_ingredient, create, destroy,
edit, index, new, show, and update"

Greg

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs