こんにちは、ネストされたフォームに問題があります..私はそれを1時間見ていて、何を忘れているのかわかりません..
models/trainer.rb
class Trainer < ActiveRecord::Base
attr_accessible :telephone, :user_attributes
has_one :user
accepts_nested_attributes_for :user
end
models/user.rb
class User < ActiveRecord::Base
belongs_to :trainer
attr_accessible :email, :image_url, :name, :password_hash, :password_salt, ...
attr_accessible :password, :password_confirmation
attr_accessor :password
before_save :encrypt_password
<+ validations ...>
controllers/trainers_controller.rb
def new
@trainer = Trainer.new
@trainer.build_user
respond_to do |format|
format.html # new.html.erb
format.json { render json: @trainer }
end
end
新しいトレーナーフォームビューを表示できます(すべてのユーザー列をネストして追加しました)が、CREATEを押すと取得します
Can't mass-assign protected attributes: user
どうしたの ?ありがとうございました
編集:私のdbスキーマは次のようになります
[users]
id
trainer_id
name
surname
[trainers]
telephone
ここで、誰かが興味を持っている場合は、シンプルなアプリをアップロードしました:) https://github.com/ScottHiscock/NestedForm