Ruby on rails 回形针发送方法,';缺少所需的属性存取器;标识(照片)(文件)名称';

Ruby on rails 回形针发送方法,';缺少所需的属性存取器;标识(照片)(文件)名称';,ruby-on-rails,paperclip,Ruby On Rails,Paperclip,我正试着用回形针把东西粘在一起。在本例中,将身份照片发送给人物模型 所以,我的档案中有: gem "paperclip", :git => "git://github.com/thoughtbot/paperclip.git" gem 'aws-sdk' 我的人.rb class Person < ActiveRecord::Base belongs_to :user has_attached_file :identity_photo end 通过这一行,我将参数发送到模型。

我正试着用回形针把东西粘在一起。在本例中,将身份照片发送给人物模型

所以,我的档案中有:

gem "paperclip", :git => "git://github.com/thoughtbot/paperclip.git"
gem 'aws-sdk'
我的人.rb

class Person < ActiveRecord::Base
 belongs_to :user
 has_attached_file :identity_photo
end
通过这一行,我将参数发送到模型。但我明白了:

 Person model missing required attr_accessor for 'identity_photo_file_name'

因此,我不知道如何处理该异常,有什么想法吗?

问题主要发生在数据库中没有所有四个必需的列时。如果是这种情况,请尝试运行以下命令:

rails generate paperclip person identity_photo
rake db:migrate  
如果不是这样,那么您可能需要在许可证参数中列出白名单
:identity\u photo\u file\u name

class PersonController < ApplicationController
  .....
  private
    def person_params
      params.require(:person).permit(:xxxxx, :identity_photo, :identity_photo_file_name)
    end
end
class PersonController
您是否运行了以确保
身份\u照片\u文件名
列位于
人员
表中?如果您明确添加
属性访问器
会发生什么变化?我没有personcontroller,正如我所写的,我只有一个注册控制器,并且我正在接收这样的参数
code
{person_identity_photo'=>#}我只是使用'send'向模型发送参数。顺便说一句,已经检查了迁移以及一切正常。因此您需要在注册控制器的persons_属性中传递它们,例如:persons_attributes=>{:identity_photo,:identity_photo_file_name}
rails generate paperclip person identity_photo
rake db:migrate  
class PersonController < ApplicationController
  .....
  private
    def person_params
      params.require(:person).permit(:xxxxx, :identity_photo, :identity_photo_file_name)
    end
end