Skip to content

Instantly share code, notes, and snippets.

@robertjwhitney
Created April 22, 2012 23:45
Show Gist options
  • Save robertjwhitney/2467573 to your computer and use it in GitHub Desktop.
Save robertjwhitney/2467573 to your computer and use it in GitHub Desktop.
Conditionally display an image instead of the file input in an ActiveAdmin has_many association.
# active_admin and formtastic seem kinda picky about displaying both the
# image and the file input together here... in fact, it seems like this
# is the ONLY way to do this? Adding anything else after the image_tag squashes it.
ActiveAdmin.register Film do
form do |f|
f.inputs "Film" do
f.input :title
end
f.has_many :stills do |film_still_form|
if film_still_form.object.new_record?
film_still_form.input :photo, :as => :file
else
image_tag film_still_form.object.photo.url(:thumbnail)
end
end
f.buttons
end
end
ActiveAdmin.register Still do
belongs_to :film
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment