Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Carrierwave with Active Admin

Did any of you guys manage to get Active Admin with Carrierwave working?

When I installed AA everything worked fine but the image file upload fields were plain text fields so added following:

ActiveAdmin.register Club do
  form do |f|
    f.inputs "Club" do
      f.input :league
      f.input :name
      f.input :image, :as => :file
      f.input :approved
    end
    f.buttons
  end
end

Now it's displayed as a file upload field and I can select a file but after I submitted the form nothing changed. There's still no image and the image field is empty. Anyone knows what else to do to get it working?

like image 441
Cojones Avatar asked Nov 25 '11 12:11

Cojones


2 Answers

Finally found the problem.

form do |f|

needs to become:

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

I still don't know why console is not working but well, at least I can upload new images now :) Thanks a lot for the help, bruno077!

like image 102
Cojones Avatar answered Sep 18 '22 15:09

Cojones


Yes, it works without an issue, remember to set the attr_accessible if you haven't. According to your configuration, you should have the following code in your model:

#app/models/club.rb

class Club < ActiveRecord::Base
  attr_accessible (previous list), :image #If exists
  mount_uploader :image, ImageUploader
end

And of course you should have generated the Image uploader with

rails generate uploader image

Edit: you can follow Ryan's railscast if you have any issue. That's what I did for my ActiveAdmin app with Carrierwave

like image 45
bruno077 Avatar answered Sep 19 '22 15:09

bruno077