Created
August 2, 2012 19:45
-
-
Save eileencodes/3240041 to your computer and use it in GitHub Desktop.
adding category selectors to active admin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
index do | |
column :title, :sortable => :title do |post| | |
link_to post.title, [:edit_admin, post] | |
end | |
column :categories do |post| | |
table_for post.categories.order('title ASC') do | |
column do |category| | |
link_to category.title, [ :admin, category ] | |
end | |
end | |
end | |
default_actions | |
end | |
show do | |
attributes_table do | |
row :title | |
row :content | |
table_for post.categories.order('title ASC') do | |
column "Categories" do |category| | |
link_to category.title, [ :admin, category ] | |
end | |
end | |
end | |
end | |
form do |f| | |
f.inputs "Add/Edit Post" do | |
f.input :title | |
f.input :content | |
f.input :categories, :as => :check_boxes | |
end | |
f.buttons | |
end |
I am doing my first Rails app and have a join table that is used for many-to-many relationships of Recipes and their Categories. For the join table to work, I have read on other blogs not to have auto-incrementing IDs on each table line. So the join table has only category_id and recipe_id. Now standard RESTful routing for editing an item is to pass an ID for the record. Without any IDs, how can I create an edit page for the lines in this join table? Thanks for any assistance.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello Chewy,
a little late for an answer after 3 months, but you can provide a :member_label => :name parameter to point to another method on the models within the collection. In your case it would be
f.input :categories, :as => :check_boxes, :member_label => :description
I got this information from the formtastic sources used by Active Admin
https://github.com/justinfrench/formtastic/blob/master/lib/formtastic/inputs/check_boxes_input.rb
Regards,
Karsten