简体   繁体   English

rails 4 paperclip:缺少必需的attr_accessor

[英]rails 4 paperclip: missing required attr_accessor

I have a problem with paperclip and rails 4. When uploading an image, I get the following error: 我有回形针和导轨4的问题。上传图像时,我收到以下错误:

Image model missing required attr_accessor for 'pic_file_name'

When adding the recommended attr_accessors 添加推荐的attr_accessors时

  attr_accessor :pic_file_name
  attr_accessor :pic_content_type
  attr_accessor :pic_file_size
  attr_accessor :pic_updated_at

the record is saved but the :pic column is empty, nothing was uploaded. 记录已保存但是:pic列为空,没有上传任何内容。

I also tried whitelisting :pic_file_name 我也试过白名单:pic_file_name

 private
    # Use callbacks to share common setup or constraints between actions.
    def set_image
      @image = Image.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def image_params
      params.require(:image).permit(:title, :pic, :pic_file_name)
    end

but no success. 但没有成功。

Any ideas what is wrong here? 任何想法在这里有什么不对?

I have solved this by creating a new column 我通过创建一个新列来解决这个问题

 def change
    add_column :images, :pic_file_name, :string
  end

might be necessary for rails 4 apps, don't know. 对于rails 4应用程序可能是必要的,不知道。 Works now. 现在工作。

Try implementing pic_file_name 尝试实现pic_file_name

def pic_file_name
 pic
end

def pic_file_name(file_name)
 pic = file_name
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM