Rails 3.2.3 アプリでは、attr_encrypted の danpal によるフォークである attr_encryptor を使用しています。hereの指示に従っていますが、新しいPatient
レコードを作成しようとすると、次のエラー メッセージが表示されます。
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
コントローラーのメソッドは次のようになりcreate
ます。Patient
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
私は何を間違っていますか?助けてくれてありがとう!