Answer the question
In order to leave comments, you need to log in
How to set up paperclip correctly?
I'm using gem Paperclip. I want to display an image on the client, but in the end it gives 404. And on the client, I get the response as "text/html", although in theory it should be "image/png". What is done wrong?
controller:
class PhotosController < ApplicationController
def index
@photos = Photo.all
array = @photos.map do |photo|
photo_push = {
users_id: photo.users_id,
photo: photo.photo.url
}
photo_push
end
render json: array
end
private
def photo_params
params.permit(
:users_id,
:photo
)
end
end
class Photo < ActiveRecord::Base
self.primary_key = "users_id"
attr_accessible :photo
belongs_to :user
has_attached_file :photo
validates_attachment_content_type :photo, content_type: ["image/jpg", "image/jpeg", "image/png"]
end
[{"users_id":36,"photo":"/photos/original/missing.png"},
{"users_id":1,"photo":"/photos/original/missing.png"},
{"users_id":1428,"photo":"/photos/original/missing.png"}]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question