【发布时间】:2013-07-21 16:20:30
【问题描述】:
我正在尝试使用 Paperclip 上传一张图片,因为它有很多并且属于与“图片”的关系
我确定 imagemagick 等已正确安装,因为我在这个项目中有更多的图片上传器可以工作,不同的是这个有很多关系。
我没有在控制台中收到“正在保存的附件”。所以我的想法是强参数完全忽略了这一点。
在主题控制器中:
params.require(:topic).permit(:id, :title, :content, :active, pictures_attributes: [:image, :id, :_destroy] )
在主题模型中:
has_many :pictures, dependent: :destroy
accepts_nested_attributes_for :pictures, allow_destroy: true
validates :title, :content, presence: true
图片模型:
belongs_to :topic
has_attached_file :image,
:styles => { :medium => "400x400#", :thumb => "200x200#", :small => "50x50#" },
:default_url => ActionController::Base.helpers.asset_path('missing.png')
我知道这方面还有很多其他的话题,只有都是rails 3,并且设置'attr_accessible'的方式不同
【问题讨论】:
-
你试过回形针的rails-4分支吗?
-
不,因为这必须有效,因为在其他项目上,这不是问题。但是这次我设法得到了一些错误。 “未经许可的参数:title_text,image”,这是正确的:因为我没有严格遵循许可参数,但没有发生错误。 “params.require(:topic).permit(:id, :title, :content, :active, pictures_attributes: { picture: [:image, :title_text]} )”,我已经尝试了所有方法,但正确的方法我猜..