1

I'm attempting to install CarrierWave gem on ActiveAdmin in rails, and the setup seemed easy enough. However, when I attempt to upload a test image to the /public/uploads directory, the image isn't saved. What's more irritating is the fact that there is no exception being raised, so I don't know where to look in order to find the issue. I can create a post, browse for an image, select that image, and submit the post in order to be saved, but I still end up with IMAGE: EMPTY on the show page in ActiveAdmin as shown below. In the image, I wrote a lorem ipsum post that included an image, and I saved it.

How to I actually get the uploader to upload?


ruby 1.9.3p547 (2014-05-14 revision 45962) [x86_64-darwin10.8.0]

Rails 4.1.6


This is the show page for a single Post object within ActiveAdmin

Image not uploading


This is a full page screenshot of the form in question

full page

The same form, but zoomed in. Obviously, I wasn't trying to upload an image in this screenshot.

zoomed in on form


/app/uploaders/image_uploader.rb

class ImageUploader < CarrierWave::Uploader::Base

    storage :file

    def store_dir
        "public/uploads"
    end

end

/app/models/post.rb

class Post < ActiveRecord::Base

    belongs_to :category

    scope :rails, -> { where(category_id: 1) }

    extend FriendlyId
    friendly_id :title, use: [:slugged, :finders]

    mount_uploader :image, ImageUploader

end
elersong
  • 756
  • 4
  • 12
  • 29
  • There could be a number of things wrong here, let's start with rails version and let's see your form that's used to create your record – Richlewis Sep 25 '14 at 20:56
  • Okay, @Richlewis, I updated the question. Thank you for reaching out to help. I'm completely stranded until I can figure this piece out. – elersong Sep 25 '14 at 22:21

1 Answers1

0

After a couple more hours of searching, I found the inspiration for an answer in another question, which you can find here.

The reason I wasn't getting a result at all was because I had not permitted the application to accept an :image in the app/admin/post.rb file. Now, I still don't know why there was no error raised (or even a line logged to the console), but fixing the problem of getting an upload is as simple as permitting the upload parameter as follows:

permit_params :title, :slug, :blurb, :content, :category_id, :image

When I posted this question, I had not added in that last :image, so my application was simply throwing away that parameter instead of saving it within the file system with the rest of the post.

Community
  • 1
  • 1
elersong
  • 756
  • 4
  • 12
  • 29
  • 1
    That was going to be my next point, but well done for figuring it out... If you look in the console when you submit the record you will notice all the Params being posted, and any Params that are not permitted will be shown as "unpermitted params", or at least something like that, so even though you don't see any errors in your view, your console is your friend, oh and puts is very useful too, though I ise awesome print which I find even better – Richlewis Sep 26 '14 at 05:28
  • Oh and the next thing your going to want to permit is _destroy so you can delete the images – Richlewis Sep 26 '14 at 05:29
  • How would I permit that? Simply add `_destroy` to the list of `permit_params` and nothing else? – elersong Sep 26 '14 at 17:01
  • I get a long list of errors when I do that. Should I have some sort of action or block in that file to give me the delete functionality? Like a button? – elersong Sep 26 '14 at 17:39
  • Well you need to have a checkbox in your form for when editing, check the docs for specifics but I'll post an answer up with example code when I'm at a pc next, for now just remove it unless you sort it out – Richlewis Sep 26 '14 at 17:57
  • Cool! It's currently commented out, and I'm excited to learn what you've got for me! – elersong Sep 26 '14 at 18:02