3
votes

First of all, these are my environment versions: Rails: 4.1.0 Ruby: 2.1.1p76 Paperclip: 4.1

I created a scaffold (rails g scaffold Entry description:text) and further added Paperclip to the then existing model (rails g paperclip entry image).

Afterwards I migrated and everything worked fine so far. Now when I upload an image it just doesn't display, instead "/images/original/missing.png" get's shown and there's no record of the image I just uploaded at all.

This is my model (models/entry.rb):

class Entry < ActiveRecord::Base
  has_attached_file :image,
        :path => ":rails_root/public/images/:class/:attachement/:id/:basename.:extension",
        :url => "/images/:class/:attachement/:id/:basename.:extension"

end

My view (show.html.slim):

p#notice = notice

p
  strong Description:
  = @entry.description
  = image_tag @entry.image.url

= link_to 'Edit', edit_entry_path(@entry)
'|
= link_to 'Back', entries_path

I have ImageMagick installed and even set the Paperclip.options within my development.rb. I have no idea what I am missing here, it just doesn't seem to upload any images whatsoever, nor throw out any error messages.

2

2 Answers

1
votes

After a little more research and a few cold drinks I found the solution!

It's necessary to either explicitly allow certain formats to get uploaded OR remove the verification check (I recommend this for development). Doing this is as simple as adding the following line to your model (for me, entry.rb) (SOURCE: https://stackoverflow.com/a/21898204/3686898)

do_not_validate_attachment_file_type :image

Also, I added another check in my controller (same as attr_accessible in earlier Rails versions):

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_entry
      @entry = Entry.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def entry_params
      params.require(:entry).permit(:description, :image)
    end

Alrighty, I hope this helps someone out :) (Always remember to have a look at your server-logs. It provides golden information!)

0
votes

Check your :path => ":rails_root/public/images/:class/:attachement/:id/:basename.:extension"

make sure that is tracing back to where the image is stored