What I am trying to do is create partial that will be invoked by
a :show_product action under the :admin controller.
This partial is meant to have a list of categories and checkboxes next
to each category. I want to set it up so when someone checks/unchecks
a category, it does something like category.products < self
The models for both Category and Product have a hmabt relationship w/
each other.
The code I''ve got so far is:
------------
# show_product.rhtml
<%= render :partial => "categories", :product => @product
%>
# _categories.rhtml
<% if @categories %>
	<% for category in @categories %>
	<div style="clear:both">
		<% form_for :category, category, :url => { :action =>
"update_product_category" }, :id => category.id do |f| %>
			<%= f.check_box :name %><%= f.label category.name %>
	    <% end %>
	</div>
	<% end %>
	<br /><br />
<% else %>
	<p>No categories found.</p>
<% end %>
# admin_controller.rb
  def categories
    @categories = Category.find(:all)
  end
-------------
The output from currently is:
<div style="clear:both">
  <form action="/admin/update_product_category"
method="post">
    <div style="margin:0;padding:0"><input
name="authenticity_token"
type="hidden" value="a265861***" /></div>
    <input id="category_name" name="category[name]"
type="checkbox"
value="1" />
    <input name="category[name]" type="hidden"
value="0" />
    <label for="category_Men">Men</label>
  </form>
</div>
QUESTIONS:
- How do I set up an observe_form or observe_field so that if someone
clicks on the a checkbox, it calls the action :update_product_category
and passes it the parameter of @product.id and category.id?
- Why does the check_box code also produce a hidden field? If I remove
the check_box code, it doesn''t produce the hidden field any more.
- What''s up with the authenticity_token?
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---