I am trying to upload multiple photos using carrierwave and activeadmin gem. But the problem is Rails says there is Unpermitted parameter: photos
, even though I have added photos to permit_params
of activeadmin gem.
#app/admin/apartment_post.rb
Code:
ActiveAdmin.register ApartmentPost do
permit_params :title, :max_stay, :bed_configuration, :number_of_guests,
:rate, :features, :description, photos: []
form(html: { multipart: true }) do |f|
f.inputs do
f.input :title
f.input :max_stay
f.input :bed_configuration
f.input :number_of_guests
f.input :rate
f.input :features
f.input :description
f.input :photos, as: :file, multiple: true
end
f.actions
end
end
#app/model/apartment_post.rb
Code:
class ApartmentPost < ApplicationRecord
mount_uploaders :photos, PhotoUploader
validates :title, :max_stay, :bed_configuration, :number_of_guests,
:rate, :features, :description, presence: true
end
schema.rb
Code:
create_table "apartment_posts", force: :cascade do |t|
t.integer "max_stay", null: false
t.string "bed_configuration", null: false
t.integer "number_of_guests", null: false
t.float "rate", null: false
t.string "features", null: false
t.string "description", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "title", null: false
t.json "photos"
end
The photo_uploader.rb
file is default as set by carrierwave.
Any help is highly appriciated, Thank You.