2013-01-20 69 views
1

我使用兩種資源色器件,管理員和用戶,與大師不能大規模指派保護屬性regristration創建設計

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 

上的routes.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' 

如果有人問我爲什麼我不使用cancan或角色用戶進行設計?我想試試這個。 如何解決我的問題,誰能幫助我?感謝的

+1

你保存你的'user.rb'文件? –

+0

是的,我做了..並重新啓動rails,但不工作 – GeekToL

+0

on rails console :guru_attributes => {:namaguru =>「maman」}}←[1m←[36m(1.0ms)←[0m←[1mBEGIN←[ 0m ←[1m←[35m(1.0ms)←[0m COMMIT => {:guru_attributes => {:namaguru =>「maman」}} – GeekToL

回答

0

好吧,我解決我的問題 在上面添加這個高清創建

@user = User.new(params[:user]) 
@user.guru.update_attributes(params[:guru]) 
if @user.save && @user.guru.update_attributes(params[:guru]) 
相關問題