1

This problem i have been trying to solve with the help of stack over websites. But unfortunately i can't do so. So i decided to ask a helping hand instead.

I have tried all those links to solve this problem. But none of them work.

    http://stackoverflow.com/questions/25934465/rails-paperclip-not-showing-image
    http://stackoverflow.com/questions/9170335/paperclip-images-not-displaying-in-rails-app
    http://stackoverflow.com/questions/23971226/rails-image-not-showing-up-with-paperclip
    http://stackoverflow.com/questions/31348628/paperclip-not-showing-image-even-though-url-images-in-correct-places
    http://stackoverflow.com/questions/7425001/specifying-missing-png-in-paperclip
    http://stackoverflow.com/questions/25249252/paperclip-where-to-place-the-
    missing-png-default-image
    http://stackoverflow.com/questions/38734116/ruby-paperclip-how-to-get-missing-png-to-work

Now my problem is that it's always displaying a square image saying missing.

Below is my code

Recipe.rb

 class Recipe < ApplicationRecord

        has_attached_file :image, styles: { medium:  "400x400#" },
       :path => ":rails_root/public/system/:attachment/:id/:style/:filename",
       :url => "/system/:attachment/:id/:style/:filename"

      validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/

      end 

Recipe's show.html.haml

= image_tag @recipe.image.url(:medium, class: "recipe_image")

Recipe's new.html.haml

= simple_form_for @recipe, html: { multipart: true } do |f|
  - if @recipe.errors.any?
    #errors
      %p
        = @recipe.errors.count
        Prevented this recipe froms saving
      %ul
        - @recipe.errors.full_messages.each do |msg|
          %li= msg
  .panel-body
    = f.input :title, input_html: { class: 'form-control' }
    = f.input :description, input_html: { class: 'form-control' }
    = f.input :image, input_html: { class: 'form-control' }

    = f.button :submit, class: "btn btn-primary"
Suresh
  • 341
  • 2
  • 7
  • 18
  • The title of this post does not describe the actual problem at hand. Also should describe the problem to be solved at the top of the question – Alexander Patrikalakis Apr 02 '17 at 05:41
  • You gave your class as second param. Shoudln't it be '= image_tag @recipe.image.url(:medium), class: 'recipe-image''? – Kevin Etore Apr 02 '17 at 06:24
  • @KevinEtore, tried and not working. – Suresh Apr 02 '17 at 06:47
  • Did the image actually get saved in the database? – Kevin Etore Apr 02 '17 at 06:50
  • Nope, it didn't save into the database. i also added the :image into my recipe_params. But the column inside my Recipe table has image_file_name. – Suresh Apr 02 '17 at 06:57
  • If it didn't save properly to the database it's quite normal you won't see it in the view right? Did you run `rails generate paperclip recipe image`? And show us the form where your adding the image. – Kevin Etore Apr 02 '17 at 07:00
  • As the docs state (https://github.com/thoughtbot/paperclip#user-content-edit-and-new-views-with-simple-form) when using simple_form you should use the syntax `= f.input :image, as: :file` as a sidenote. – Kevin Etore Apr 02 '17 at 07:16
  • isn't working!! – Suresh Apr 02 '17 at 07:23
  • make `url and path` same. also paste your paperclip interpolation file here – Mihir Kumar Thakur Apr 02 '17 at 12:38
  • Paperclip.options[:command_path] = "C:\Program Files\ImageMagick-6.9.8-Q16-HDRI\images" is this the correct path for the Paperclip to know my ImageMagick? – Suresh Apr 04 '17 at 15:06

1 Answers1

-1

been having the same problem for a while but fixed it myself just now.

what i did:

look through your site folder to see where the images are saved. i.e. mine were saving in a different path to what was showing in my post.rb file. troubleshoot it is all i can suggest. right click and inspect element on the broken image and compare

i adjusted accordingly and it works fine now :)

Ethan Bradberry
  • 107
  • 1
  • 14