I am having trouble with my first join-table for a many to many relationship.
class Category < ActiveRecord::Base
has_and_belongs_to_many :users
end
class User < ActiveRecord::Base
has_and_belongs_to_many :categories
end
And I have added a join table:
create_table "categories_users", :id => false, :force => true do |t|
t.integer "category_id", :null => false
t.integer "user_id", :null => false
end
Can someone point me to an example of the form that I would use to add a user to a category? Do I need a separate restful controller for ‘categories_users’? I have an impulse to add method to my category controller called “add user”, but I’m not sure if that is wise for an otherwise RESTful controller.
I’m using simple_form and I finally found in the documentation there what to do. So using simple_form, the form would look like this:
No need to add a controller or separate form. Yay!