Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 使用attr_encrypted(attr_encryptor)gem时发生MassaSignmentSecurity错误_Ruby On Rails 3_Mass Assignment_Attr Encrypted - Fatal编程技术网

Ruby on rails 3 使用attr_encrypted(attr_encryptor)gem时发生MassaSignmentSecurity错误

Ruby on rails 3 使用attr_encrypted(attr_encryptor)gem时发生MassaSignmentSecurity错误,ruby-on-rails-3,mass-assignment,attr-encrypted,Ruby On Rails 3,Mass Assignment,Attr Encrypted,对于我的rails 3.2.3应用程序,我使用的是attr_encryptor,它是由attr_encrypted的danpal开发的一个分支。我已按照给出的说明进行操作,但在尝试创建新病历时收到以下错误消息: 正如说明所说,我在我的Patients表中添加了加密的{field}、加密的{field}salt和加密的{field}iv列,同时删除了它们的非加密对应列 患者模型如下所示: class Patient < ActiveRecord::Base attr_accessible

对于我的rails 3.2.3应用程序,我使用的是attr_encryptor,它是由attr_encrypted的danpal开发的一个分支。我已按照给出的说明进行操作,但在尝试创建新病历时收到以下错误消息:

正如说明所说,我在我的Patients表中添加了加密的{field}、加密的{field}salt和加密的{field}iv列,同时删除了它们的非加密对应列

患者模型如下所示:

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
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

我做错了什么?提前感谢您的帮助

您需要使用attr_accessible和attr_encrypted标记这些属性,因为后者并不意味着前者


这也可能与日期字段相关:

您需要使用attr\u accessible和attr\u encrypted标记这些属性,因为后者并不意味着前者

这也可能与日期字段相关:

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