我期待着一些混合mongoid和simple_form的麻煩(我認爲 - 同樣的問題實際上是其他表單構建器)。我有一個小形式的關係,有點像mongoid,表單構建器和關係
f.input :author, collection: User.all, as: :select
,當我提交表單沒有作者選擇我看到異常喜歡
NoMethodError in ExamplesController#update
undefined method `id' for "":String
如此悲傷:(我看到 - simple_form提交「」(空字符串),但不是零到控制器當然 - 。?我可以驗證從表單生成每個PARAM,但我不知道這是很好的解決方案,你能推薦我一些
UPD(模型結構) :
user.rb
class User
include Mongoid::Document
include Mongoid::Timestamps
has_many :examples, :inverse_of => :author
has_many :examples, :inverse_of => :responsible_person
end
example.rb
class Example
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::MultiParameterAttributes
field :title, type: String
field :description, type: String
belongs_to :author, :class_name => "User"
belongs_to :responsible_person, :class_name => "User"
validates_presence_of :title, :description, :author
attr_accessible :title, :description, :author, :responsible_person
end
給人以代碼結構更新您的模型結構 – abhas
:) –