【发布时间】:2017-01-12 05:52:13
【问题描述】:
代码:
商业模式
class Business < ApplicationRecord
has_many :business_categories
has_many :categories, through: :business_categories
......
end
类别模型
class Category < ApplicationRecord
has_many :services
has_many :business_categories
has_many :businesses, through: :business_categories
.....
end
业务类别模型
class BusinessCategory < ApplicationRecord
belongs_to :business
belongs_to :category
has_many :business_category_services
has_many :services, through: :business_category_services
....
end
class Service < ApplicationRecord
belongs_to :category
end
我想设计的表格请看下面的快照。
please have a look on snapshot
form do |f|
f.inputs 'Business' do
f.input :name
f.input :category_ids, as: :check_boxes, collection: Category.all.map{|category| [category.name, category.id]}
f.has_many :business_categories, :class=>'select_category', :heading=>'Services', :new_record=> true do |business_category|
business_category.input :service_ids, as: :check_boxes, collection: Service.all.map{|service| [service.name, service.id]}, :input_html => { :class => 'services_checkboxes'}
end
in the snapshot 如您所见 - 所有类别和服务复选框都来自类别和服务表,通过 Category.all 和 Service.all.
service_ids 应该是动态的,我的意思是我应该只看到那些基于步骤 2 中选择的类别的服务,而不是全部。
我该如何实现它?
【问题讨论】:
标签: ruby-on-rails activeadmin ruby-on-rails-5 form-for