I want to upload multiple images in form by using active storage but it gives an permit params issue Unpermitted parameter: :avatars
params.require(:poi).permit(:title, :description,avatars: [])
In _form.html.erb
,
<%= form.file_field :avatars %>
In poi.rb
,
has_many_attached :avatars
In controller,
@poi = Poi.new(poi_params)
respond_to do |format|
if @poi.save
format.html { redirect_to @poi, notice: 'Poi was successfully created.' }
format.json { render :show, status: :created, location: @poi }
else
format.html { render :new }
format.json { render json: @poi.errors, status: :unprocessable_entity }
end
end
How can I fix this issue?
Refer here . You have has_many_attached
relation, Your code will work only for has_one_attached
relation.
For has_one_attached
,
<%= form.file_field :avatars %>
For has_many_attached
,
<%= form.file_field :avatars, multiple: true %>
For direct upload,
<%= form.file_field :attachments, multiple: true, direct_upload: true %>
Add multiple: true
in your file field. The file_input should look like this:
<%= form.file_field :avatars, multiple: 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.