【发布时间】:2013-10-13 16:42:43
【问题描述】:
我有一个嵌套资源,如下所示:user/1/photos/new
resources :users, only: [] do
resources :photos, except: [:show]
end
我的 form_for 如下:
= form_for([@user, @photo], html: { multipart: true }) do |f|
.inputs
= f.file_field :attached_photo
.actions
= f.submit :submit
我认为我遇到的问题是强参数:
def photo_params
params.require(:photo).permit(:title, :attached_photo)
end
当我点击表单上的提交按钮时,我收到以下错误:
PhotosController#create 中的 ActionController::ParameterMissing 未找到参数:照片
我使用的是回形针,所以在我拥有的模型中:
has_attached_file :attached_photo
请指教。
【问题讨论】:
-
你的 Rails 服务器输出显示的参数是什么?
-
如果我为标题添加一个文本字段。然后参数如下: "photo"=>{"title"=>""}, "commit"=>"submit", "painter_id"=>"1" 似乎 :attached_photo 没有通过。
-
用文件字段上传文件还是不通过吗?我在我的一个应用程序上使用回形针照片上传进行了测试,如果实际使用文件字段选择了文件,则它仅包含参数。
-
那么问题是如何确保附上照片
-
您的哪个型号有
has_attached_file :attached_photo代码?
标签: ruby-on-rails strong-parameters