通过Active Admin使用HABTM或Has_many
我已经阅读了很多关于使用活动管理员与has_many通过关联的post,但我没有得到所需的结果。 基本上我有2个模型“会议”和“帐户”。 我需要为会议分配多个帐户,为帐户分配多个会议。 我使用HABTM或has_many对我来说无关紧要。 我只需要在创建新会议时能够看到下拉选择选项,反之亦然。
帐户模型
class Account :destroy has_many :conferences, :through => :conferenceaccount end
会议模式
class Conference :conferenceaccount end
会议账户模型
class Conferenceaccount < ActiveRecord::Base belongs_to :conference belongs_to :account attr_accessible :account_id, :conference_id end
会议管理模型
ActiveAdmin.register Conference do form do |f| f.inputs "Details" do # Project's fields f.input :conferencename f.input :address f.input :city f.input :state f.input :website f.input :phone f.input :eventdatestart f.input :eventdateend f.input :industry end f.has_many :conferenceaccounts do |app_f| app_f.inputs "Conferences" do if !app_f.object.nil? # show the destroy checkbox only if it is an existing appointment # else, there's already dynamic JS to add / remove new appointments app_f.input :_destroy, :as => :boolean, :label => "Destroy?" end app_f.input :account # it should automatically generate a drop-down select to choose from your existing patients end end f.buttons end end
我一直收到以下错误
ActionView::Template::Error (undefined method `klass' for nil:NilClass): 1: insert_tag renderer_for(:new) app/admin/conferences.rb:14:in `block (2 levels) in '
我怎样才能解决这个问题?
谢谢。
您是否尝试在会议模型中添加以下行?
# conference.rb attr_accessible : conferenceaccounts_attributes has_many :conferenceaccounts # This line after your your relations accepts_nested_attributes_for : conferenceaccounts, :allow_destroy => true
请参阅: 接受has_many关系的嵌套属性
当使用has_many through: :some_model
,请确保定义has_many on :some_model
,例如:
如果你有:
class Account < ActiveRecord::Base has_many :conferences, :through => :conferenceaccount end
将其转换为:
class Account < ActiveRecord::Base has_many :conferences, :through => :conferenceaccount has_many :conferenceaccount # <- added end
- Rails管理员与活动管理员:Rails管理生成工具
- ActiveAdmin – 未初始化的常量AdminUser
- 将根页面设置为activeAdmin默认登录页面
- ActiveAdmin自定义belongs_to的表单
- 如何使用多个Active Admin实例来完成单独的模型
- 使用ActiveAdmin和Friendly_id时的ActiveRecord :: ReadOnlyRecord
- rails activeadmin下拉菜单新建和编辑表格
- 计算Active Admin仪表板(Rails,Active admin 1.0,Postgresql数据库,postgres_ext gem)中序列化属性(数组)中值的出现次数
- 使用主动管理员cancan进行范围界定