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 %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.label :prod_type %><br />
<%= f.text_field :prod_type %>
</p>
<p>
<%= f.label :min_visit %><br />
<%= f.text_field :min_visit %>
</p>
<p>
<%= f.label :max_visit %><br />
<%= f.text_field :max_visit %>
</p>
<p>
<%= f.label :price %><br />
<%= f.text_field :price %>
</p>
<p>
<%= f.label :visible %><br />
<%= f.text_field :visible %>
</p>
<div id="ingredients">
<%= 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 %>
</div>
<p><%= f.submit "Submit" %></p>
<% 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
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.