即使使用开箱即用的基本教程单图示例,Carrierwave也不会保存,书写或上传图像。代码的所有(基本)位都在正确的位置,并且它不会在前端发出任何错误消息,看起来可以工作,保存新的'newsitem',但没有选定的图像。Rails 4:为什么Carrierwave没有上传/写入/保存图像?
控制台抛出了:
Started PATCH "/newsitems/63" for ::1 at 2015-08-08 22:24:43 +0200
Processing by NewsitemsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"gbbna69pcZY1h8fG5s/4CdbFw48D0FakaWehZURUSFcfPPJcuamyduFLtazYvjlRrhXgurEirxceUSxoK4RQwg==", "newsitem"=>{"slug"=>"asdfasf", "source"=>"", "url"=>"", "item"=>"asdfasdf", "story_ids"=>["3", ""], "region_ids"=>["2", ""], "category_ids"=>["5", ""], "main"=>"24m-podemos-ballot-papers.jpg"}, "commit"=>"Update Newsitem", "id"=>"63"}
Newsitem Load (0.1ms) SELECT
blah, blah, blah…
最重要的是内,为您节省从一路向右滚动,它拿起:
"main"=>"24m-podemos-ballot-papers.jpg"
但是再往PATCH声明,我们得到:
SQL (0.4ms) UPDATE "newsitems" SET "main" = ?, "updated_at" = ? WHERE "newsitems"."id" = ? [["main", nil], ["updated_at", "2015-08-08 20:24:43.490668"], ["id", 63]]
'新','编辑'和'显示'页面不会引发任何错误。 '新'和'编辑'似乎让我添加图像,它保存了newsitem,然后将其显示在新页面上,但根本没有图像。因此,表单域和数据库之间的某处不起作用。
我检查,以确保 ':主' 是newsitems控制器参数:
def newsitem_params
params.require(:newsitem).permit(:item, :main, :source, :slug, :url, :region_ids => [], :category_ids => [], :story_ids => [])
end
任何想法?
很明显,文件从服务器日志传递到参数中。现在为了更新,我确定你将'newsitem_params'传递给update_attributes方法。你可以验证'newsitem_params'中的内容吗?这应该是第一个看的地方。 – Alfie
呃,不知道你的意思,Alfie ...你是什么意思“验证newsitem_params中的内容”?不是'def newsitem_params'位? –
检查'newsitem_params'方法返回的内容。用户Rails记录器或它的东西。 – Alfie