2012-06-08 31 views
2

时候对于我的导轨3.2.3的应用程序,我使用attr_encryptor,这是danpal的attr_encrypted叉子。我按照说明书给出here,但是当我尝试创建一个新的Patient记录我收到以下错误消息:MassAssignmentSecurity错误使用attr_encrypted(attr_encryptor)宝石

ActiveModel::MassAssignmentSecurity::Error in PatientsController#create 

Can't mass-assign protected attributes: mrn, last_name, first_name, date_of_birth(1i), date_of_birth(2i), date_of_birth(3i) 

作为指示说,我已经加入encrypted_#{field}encrypted_#{field}_saltencrypted_#{field}_iv列我的Patients表,同时删除其未加密的对应表。

Patient模式是这样的:

class Patient < ActiveRecord::Base 
    attr_accessible :age, :gender 
    attr_encrypted :last_name, :key => 'key 1' 
    attr_encrypted :first_name, :key => 'key 2' 
    attr_encrypted :mrn, :key => 'key 3' 
    attr_encrypted :date_of_birth, :key => 'key 4' 
    # ... 
end 

我在我的Patient控制器create方法是这样的:

PatientsController < ApplicationController 
    # ... 
    def create 
    @patient = Patient.new 
    @patient.first_name = params[:patient][:first_name] 
    @patient.last_name = params[:patient][:last_name] 
    @patient.mrn = params[:patient][:mrn] 
    @patient.date_of_birth = Date.new(params[:patient]['date_of_birth(1i)'], 
             params[:patient]['date_of_birth(2i)'], 
             params[:patient]['date_of_birth(3i)']) 
    if @patient.save 
     # do stuff 
    else 
     # do other stuff 
    end 
    end 
    # ... 
end 

我在做什么错?先谢谢您的帮助!

回答