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 =>
match 'remove_from/:pid' => 'categories#remove_from', :as =>
'remove_from', :via => [:get, :post]

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"=>"✓",
"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?

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/-JOe70bMe8AJ.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
postedJun 11, '12 at 7:53p
activeJun 11, '12 at 7:53p

1 user in discussion

AK: 1 post



site design / logo © 2022 Grokbase