Chuck Callebs
Chuck Callebs

Reputation: 16431

ActiveAdmin, Formtastic, and Paperclip: Not Rendering File Dialog

I'm implementing a generic media gallery using Ruby on Rails. I've chosen ActiveAdmin to handle the administration portion of my task and it's worked well so far, except for one thing: It's not displaying the "Choose file" dialog as intended.

This is a form for my "Media" section of ActiveAdmin. I have a model called "Medium" with the following fields (in addition to id and timestamp:

My Medium model looks like this:

class Medium < ActiveRecord::Base
  has_and_belongs_to_many :galleries
  has_and_belongs_to_many :entities

  has_attached_file :asset, :styles => { :medium => "300x300>", :thumb => "100x100>" }

  attr_accessible :asset
end

And I'm adding it to the ActiveAdmin form like this:

  form :html => { :enctype => "multipart/form-data" } do |f|  
    f.input :asset, :as => :file
    f.buttons
  end

Here's a screencap of my ActiveAdmin page: New Medium

I see nothing wrong with how I'm implementing this. I've read that Formtastic has historically had issues with paperclip and I'm not averse to switching to attachment_fu or any other suitable solutions.

I should also note: I know that I can add in a custom partial. It's not my ideal solution, as I'd like to keep everything in the Formtastic DSL.

Thanks!

Upvotes: 2

Views: 3556

Answers (4)

Ryan Wong
Ryan Wong

Reputation: 120

the latest active admin handle it automatic

Upvotes: 1

pedrozath
pedrozath

Reputation: 2403

Or you can do:

form :html => {:multipart => true} do |f|

which is easier to remember, imho.

Upvotes: 4

Robbie Done
Robbie Done

Reputation: 1157

I use carrier wave with active admin and works as above.

Upvotes: 0

Greg Bell
Greg Bell

Reputation: 374

Formtastic requires that you wrap all calls to #input in a call to #inputs. It's definitely something that I would like to see fixed in Active Admin.

It should work if you wrap your input in a call to inputs:

form :html => { :enctype => "multipart/form-data" } do |f|  
  f.inputs do
    f.input :asset, :as => :file
  end
  f.buttons
end

Let me know if this works for you.

Upvotes: 11

Related Questions