15

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?

Cojones
  • 2,930
  • 4
  • 29
  • 41

2 Answers2

35

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!

Cojones
  • 2,930
  • 4
  • 29
  • 41
2

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

bbonamin
  • 30,042
  • 7
  • 40
  • 49
  • Hey, thanks for the answer but I got all that already... `class Club < ActiveRecord::Base` `attr_accessible :name, :image, :photo_id, :league_id, :approved, :permalink` `mount_uploader :image, IconUploader` And I, of course, have an IconUploader which worked before I introduced ActiveAdmin. What else could be missing? Sorry for the terrible formatting but it doesn't seem to like my carriage returns... – Cojones Nov 28 '11 at 18:10
  • I just realized I can't even update the image attribute in the console, there must be something else wrong... – Cojones Nov 28 '11 at 18:19
  • Does the image attribute appear in your schema.rb ? If it doesn't, you probably don't even have the attribute in the db – bbonamin Nov 28 '11 at 18:51
  • Yes, of course: create_table "clubs", :force => true do |t| t.string "name" t.string "image" ... – Cojones Nov 28 '11 at 18:52
  • Oh, by the way. Some clubs have a value in the image field but they were all created with the seeds command ("club1.image.store! ...") – Cojones Nov 28 '11 at 18:58
  • I can't seem to grasp why you would even have an issue trying to update the image field from the console. Do you have any validation going on with this attribute? I would recommend you go step by step with the linked screencast, it worked flawlessly for me. – bbonamin Nov 28 '11 at 19:02
  • I did it step by step again already but since I can't even change the image field in the console anymore it doesn't really help. Like I said it all worked before I introduced ActiveAdmin... I guess I have to go back to before I installed it. – Cojones Nov 29 '11 at 08:01