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}_salt
和encrypted_#{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
我在做什麼錯?先謝謝您的幫助!