Paperclip SEND方法,缺少人员模型attr_accessor,用于' identity_photo_file_name'

时间:2014-12-31 05:16:53

标签: ruby-on-rails paperclip

我试图用回形针来附上东西。在这种情况下,人物模型的身份照片。

所以,我在我的Gemfile中有这个:

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

my person.rb

class Person < ActiveRecord::Base
 belongs_to :user
 has_attached_file :identity_photo
end

我的参数是这样的:

Parameters: {person_identity_photo"=>#<ActionDispatch::Http::UploadedFile:0x000000090cc728 @tempfile=#<Tempfile:/tmp/RackMultipart20141230-8243-18uvxyd>, @original_filename="asdasd.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"registration_form[person_identity_photo]\"; filename=\"asdasd.png\"\r\nContent-Type: image/png\r\n">}}

我在课堂上委派字段,所以最后我要做的是:

 self.send(field, value) 

用该行我将参数发送给模型。但是我得到了这个:

 Person model missing required attr_accessor for 'identity_photo_file_name'

所以,我不确定如何处理这个异常,任何想法?

1 个答案:

答案 0 :(得分:0)

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

rails generate paperclip person identity_photo
rake db:migrate  

如果不是这种情况,那么您可能需要在许可证参数中将:identity_photo_file_name列入白名单。

class PersonController < ApplicationController
  .....
  private
    def person_params
      params.require(:person).permit(:xxxxx, :identity_photo, :identity_photo_file_name)
    end
end