0

'accepts_nested_attributes_for'を使用するフォームを保存しようとすると、'保護された属性を一括割り当てできません'エラーが発生します。モデルを正しくコーディングしたと思いますが、何を見逃したのかわかりません。何か案が?

エラー:保護された属性を一括割り当てできません:組織

user.rb

class User < ActiveRecord::Base
  belongs_to :organization

  accepts_nested_attributes_for :organization

  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  attr_accessible :email, :password, :password_confirmation, :remember_me,
                  :username, :first_name, :last_name, :organization_attributes
end

Organisation.rb

class Organization < ActiveRecord::Base
  has_many :users

  attr_accessible :address1, :address2, :city, :country, :fax, :name, :phone, :state, :zip
end

users_controller.rb

  def new
    @user = User.new
    @organization = Organization.new

    respond_to do |format|
      format.html # new.html.erb
    end
  end

  def create
    @user = User.new(params[:user])
    @organization = @user.organizations.build(params[:organization])

    respond_to do |format|
      if @user.save
        @organization.save
        format.html { redirect_to @user, notice: 'User was successfully created.' }
      else
        format.html { render action: "new" }
      end
    end
  end
4

1 に答える 1

0

この質問に対する答えに基づいて、私が望むものを得るために管理してください: Devise で Account テーブルと User テーブルの両方を使用する

ちなみに、私もSTIを使用していますが、うまく機能します。

于 2012-05-18T02:11:32.850 に答える