N
N
nzk2018-08-27 08:51:16
Ruby on Rails
nzk, 2018-08-27 08:51:16

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

model:
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

and this is what the json looks like:
[{"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 question

Ask a Question

731 491 924 answers to any question