我遇到了载波和轨道4强参数的问题.我有一个非常简单的模型,带有载波上传按钮.如果有人在没有选择要上传的文件的情况下提交上传表单,我想显示错误消息.
现在,我收到param not found:photo此消息的错误:
  # Never trust parameters from the scary internet, only allow the white list through.
    def photo_params
      params.require(:photo).permit(:image)
    end
发生此错误是因为Rails 4的强参数要求提供图像参数以提交表单,但由于用户未选择图像,因此不存在.
我无法找到解决此问题的方法,并将其重定向到相同的操作并显示错误消息.
有没有办法用强参数做到这一点?
当我尝试使用没有选择照片的表单时,这是开发日志:https: //gist.github.com/leemcalilly/09b6166ce1af6ca6c833
当我选择照片并成功上传时,这是开发日志:https: //gist.github.com/leemcalilly/1f1e584f56aef15e7af1
其他相关文件:*models/photo.rb - https://gist.github.com/leemcalilly/95c54a5df4e4ee6518da *controllers/photos_controller.rb - https://gist.github.com/leemcalilly/c0723e6dc5478b0f914d *uploaders/image_uploader.rb - https://gist.github.com/leemcalilly/5e43f6524734991773ae *views/photos/index.html.erb - https://gist.github.com/leemcalilly/a8c4c808e5e8a802933b *views/photos/_form.html.erb - https ://gist.github.com/leemcalilly/cd0fd518c1b47d9bfb62 *initializers/carrierwaver.rb - https://gist.github.com/leemcalilly/49e04fa1dda891dd108b