# Routes & Link\_to

**URL:** <https://www.ruby-forum.com/t/routes-link-to/184819>\
**Category:** Rails\
**Created:** [March 9, 2010, 2:44am UTC](https://www.ruby-forum.com/t/routes-link-to/184819 "2010-03-09T02:44:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bc79bd/32.png) [@gregm](https://www.ruby-forum.com/u/gregm)\
**Post date:** [March 9, 2010, 2:44am UTC](https://www.ruby-forum.com/t/routes-link-to/184819/1 "2010-03-09T02:44:02Z")

</div>

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
