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. I've found several other identical questions on Stack Overflow that are unanswered. Any advice would be greatly appreciated.
Create ActiveStorage tables
rails active_storage:install
Add to Model
class Photo < ApplicationRecord
has_one_attached :image_file
end
Controller (permit:image_file)
def photo_params
params.require(:photo).permit(:image_file)
end
Javascript for Direct Upload
//= 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.