[英]unable to permit a param
I'm trying to use active storage to to attach an image file to my photo model, but no matter what I try I get an error saying that the "image_file" is not permitted.我正在尝试使用活动存储将图像文件附加到我的照片 model,但无论我尝试什么,我都会收到一条错误消息,指出不允许使用“image_file”。 I've found several other identical questions on Stack Overflow that are unanswered.
我在 Stack Overflow 上发现了其他几个未回答的相同问题。 Any advice would be greatly appreciated.
任何建议将不胜感激。
Create ActiveStorage tables创建 ActiveStorage 表
rails active_storage:install
Add to Model添加到 Model
class Photo < ApplicationRecord
has_one_attached :image_file
end
Controller (permit:image_file) Controller(许可:image_file)
def photo_params
params.require(:photo).permit(:image_file)
end
Javascript for Direct Upload Javascript 直接上传
//= require activestorage
Add Direct Upload to View添加直接上传到视图
<%= f.file_field :image_file, class: 'form-control-file', direct_upload: true, required: true %>
When I hit the byebug I entered "params" which returned permitted: false
but I should have entered "photo_params which returns permitted: true
当我点击 byebug 时,我输入了返回 allowed
permitted: false
的“params”,但我应该输入了返回 allowed permitted: true
的“photo_params”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.