I have a resource Photos, which belongs to Adverts.
In ActiveAdmin, users should be able to upload Photos directly from the Advert’s edit page (obviously only once the advert has been created).
The form is generated as follows:
form do |f|
[... the usual forms ...]
f.inputs "Photos" do
f.has_many :photos, :title => "Photo" do |p|
p.input :advert, :as => :hidden, :value => Advert.find(params[:id])
p.input :title
p.input :image
end
end
end
I would like the line
p.input :advert, :as => :hidden, :value => Advert.find(params[:id])
to produce a hidden field with the ID of the Advert the user is editing, however this just produces an empty field. I’ve tried a number of other options as well, but can’t seem to figure it out.
Any hints?
You can use advert variable, which holds Advert object with id from params.
by the way, your code is invalid. You get whole Advert object, not just id. Valid code:
this should works, too