开发者

ActiveAdmin, Formtastic, and Paperclip: Not Rendering File Dialog

开发者 https://www.devze.com 2023-04-07 18:15 出处:网络
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 di

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:

  • asset_file_name
  • asset_file_size
  • asset_content_type
  • asset_updated_at

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:

ActiveAdmin, Formtastic, and Paperclip: Not Rendering File Dialog

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!


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.


Or you can do:

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

which is easier to remember, imho.


the latest active admin handle it automatic


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

0

精彩评论

暂无评论...
验证码 换一张
取 消