1

私は2つのリソースデバイス、管理者とユーザー、tatausahaとの管理者関係、および教祖とのユーザー関係を使用します

tatausahaとの管理関係についてエラーではありません

しかし、教祖とのユーザー関係でエラーが発生しました保護された属性を一括割り当てできません

モデルuser.rbで

class User < ActiveRecord::Base

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

  attr_accessible :email, :password, :password_confirmation, :remember_me, :guru_attributes

  has_one :guru 
  accepts_nested_attributes_for :guru

end

モデルguru.rbで

class Guru < ActiveRecord::Base
  attr_accessible :namaguru, :nip, :user_id
  belongs_to :user
end

Registrationusers_controller.rbで

class RegistrationusersController < Devise::RegistrationsController
  layout :layout_by_resource3
  skip_before_filter :require_no_authentication
  before_filter :authenticate_admin!
  before_filter :resource_name

  def resource_name
    :user
  end

  def new
    @user = User.new
    @user.build_guru
  end

  def create
    build_resource

    if resource.save
      if resource.is_a?(User)
        redirect_to new_userguru_registrationuser_path, :notice => "Guru was successfully created."
      else
        set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
        expire_session_data_after_sign_in!
        respond_with resource, :location => new_user_session_path
      end


    else
      clean_up_passwords resource
      respond_with resource
    end

  end


end

ルート上で.rb

 devise_for :users, :controllers => {:registrations => "registrationusers" }

そして私は次のようなエラーが発生しました

ActiveModel::MassAssignmentSecurity::Error (Can't mass-assign protected attribut
es: guru_attributes):
  app/controllers/registrationusers_controller.rb:17:in `create'

誰かが私にカンカンやロールユーザーを考案に使用しない理由を尋ねられたら?これを試してみたいです。私の問題を解決する方法、誰かが私を助けることができますか?ありがとう

4

1 に答える 1

0

わかりました、私は私の問題を解決しましたdefcreateにこれを追加します

@user = User.new(params[:user])
@user.guru.update_attributes(params[:guru])
if @user.save && @user.guru.update_attributes(params[:guru])
于 2013-01-21T02:05:24.600 に答える