我使用两个资源设计,管理员和用户,管理员与 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'
如果有人问我为什么不使用 cancan 或角色用户进行设计?我想试试这个。如何解决我的问题,有人可以帮助我吗?谢谢