简体   繁体   English

使用Paperclip和Rails 4无法保存图像

[英]Image will not save with Paperclip and Rails 4

I'm trying to use Paperclip for uploading an image for an has many and belongs to relationship with 'pictures' 我正在尝试使用Paperclip上传一个有很多的图像,并且属于与'pictures'的关系

I'm certain that imagemagick etc, is correctly installed, because i've more image uploaders in this project that works, difference is that this one has an has many relation. 我确定imagemagick等正确安装,因为我在这个项目中有更多的图像上传工作,不同的是这个有很多关系。

I'm not getting a 'Saving Attachment' in the console. 我没有在控制台中获得“保存附件”。 So my idea is that this is completely ignored by the strong parameters. 所以我的想法是强参数完全忽略了这一点。

In topicscontroller: 在topicscontroller中:

params.require(:topic).permit(:id, :title, :content, :active, pictures_attributes: [:image, :id, :_destroy] )

In Topic Model: 在主题模型中:

has_many :pictures, dependent: :destroy
accepts_nested_attributes_for :pictures, allow_destroy: true
validates :title, :content, presence: true

In Picture Model: 在图片模型中:

belongs_to :topic

has_attached_file :image,
:styles => { :medium => "400x400#", :thumb => "200x200#", :small => "50x50#" },
:default_url => ActionController::Base.helpers.asset_path('missing.png')

I know that there are many other topics about this, only all are rails 3 and is different in the way of setting 'attr_accessible' 我知道关于这个还有很多其他主题,只有所有都是rails 3,并且设置'attr_accessible'的方式不同

使用Paperclip 3.5.0版本,Rails 4的一切都很好。

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

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