Rails 3.2.3
I am trying for the first time to build an app that makes heavy use of
Javascript, but degrades gracefully.
My setup is simple:
Category HABTM Products and vice versa.
I have a view that lets the user add products to a category. At the top
of
the view is a select box of products. At the bottom is a list of all
products in the current category. Everything on the view is done in the
context of a category.
My routes look like this:
resources :categories do
member do
get ‘list_products_in’
match ‘add_to/:pid’ => ‘categories#add_to’, :as => ‘add_to’, :via
=>
:post
match ‘remove_from/:pid’ => ‘categories#remove_from’, :as =>
‘remove_from’, :via => [:get, :post]
end
end
resources :products
My “remove_from” action works fine, because I know the value of the
product
at render time, and so I can use the “remove_from_category_path” helper.
But I have the following form:
<%= form_tag add_to_category_path(@category,:pid) do %>
<%= select_tag “pid”, options_from_collection_for_select(@products,
“id”,
“identifier”), :include_blank => true %>
<%= hidden_field_tag “cid”, @category.id %>
<%= button_tag “Add”, { :id => “add_product_to_category_button” } %>
<% end %>
And this does NOT work, of course. The request looks like this:
Parameters: {“utf8”=>“✓”,
“authenticity_token”=>“rhXFK/mnqUCTnx2PZ0pnpCL+u9Jm3kYIz9IlEl4nomU=”,
“pid”=>“pid”, “cid”=>“2”, “button”=>"", “id”=>“2”}
pid=pid = FAIL
How can I write this form_tag to do what I want here? Is there some sort
of
pattern I can follow?