设计一个 model:OrganizationMember
,它是属于Organization
的。
在 organization.rb 里面:
class Organization < ActiveRecord::Base
has_many :members, class_name: :OrganizationMember
end
在 routes.rb:
resources :organizations do
resources :member, controller => "organization/members"
end
在 controller 里面,我需要用 cancan:
class Organization::MembersController < Organization::BaseController
load_and_authorize_resource :member, class: OrganizationMember, through: :organization, through_association: :members
end
在 form 里面,我需要用 form_for:
= form_for @member, url: organization_member_path(@organization, @member) do |f|
...
写起来真是累呀,大家知道有什么更好的方法吗?