【发布时间】:2016-01-20 09:57:19
【问题描述】:
我想在 simple_form <%= f.association :organisators, collection: User.all %> 和 <%= f.association :helpers, collection: User.all %> 中选择它们的来源将是存储在具有适当枚举类型的参与连接表中的用户 ID,这是一种使用 ActiveRecord 关系自动完成的方法吗?
class Participation < ActiveRecord::Base
belongs_to :user
belongs_to :event
enum kind: [:helper, :organisator]
end
class Event < ActiveRecord::Base
belongs_to :user
has_many :participations
has_many :organisators, class_name: 'Participation'
has_many :helpers, class_name: 'Participation'
end
class User < ActiveRecord::Base
has_many :events
has_many :participations
end
当我尝试保存当前版本时,它会出现:Couldn't find Participation with 'id'=1
event_params: {"helper_ids"=>["2"], "organisator_ids"=>["1"]}
【问题讨论】:
标签: ruby-on-rails ruby enums relationships