Reputation: 141
I use Rails Api 5.1.6 as a backend. As a client, I use Angular 4. All data is stored in an Oracle database. Images in the database are stored in the format "Blob". I also use the paperclip gem to work with images on Rails Api.
So when I try to display an image on the client, the error "404 not found" appears. Here is the error in the console:
GET http://localhost:4200/photos/original/missing.png 404 (Not Found)
I also tried to follow this link:
But such an error occurs (If you need, I can add a complete error here):
"#ActionController::RoutingError: No route matches [GET] "/photos/original/missing.png""
JSON:
[
{
l_users_id: 65,
photo: "/photos/original/missing.png"
},
{
l_users_id: 1,
photo: "/photos/original/missing.png"
},
{
l_users_id: 1357,
photo: "/photos/original/missing.png"
},
{
l_users_id: 1358,
photo: "/photos/original/missing.png"
},
{
l_users_id: 51,
photo: "/photos/original/missing.png"
},
{
l_users_id: 2,
photo: "/photos/original/missing.png"
},
{
l_users_id: 1360,
photo: "/photos/original/missing.png"
},
{
l_users_id: 0,
photo: "/photos/original/missing.png"
},
{
l_users_id: 1372,
photo: "/photos/original/missing.png"
},
{
l_users_id: 1371,
photo: "/photos/original/missing.png"
},
{
l_users_id: 1370,
photo: "/photos/original/missing.png"
},
{
l_users_id: 1373,
photo: "/photos/original/missing.png"
}
]
photos_controller.rb:
class PhotosController < ApplicationController
def index
@photos = Photo.all
array = @photos.map do |photo|
photo_push = {
l_users_id: photo.l_users_id,
photo: photo.photo.url
}
photo_push
end
render json: array
end
def show
@photo = Photo.find(params[:id])
photo_hash = {
l_users_id: photo.l_users_id,
photo: photo.photo.url
}
render json: photo_hash
end
end
photo.rb:
class Photo < ActiveRecord::Base
self.primary_key = "l_users_id"
has_attached_file :photo
validates_attachment_presence :photo
validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png']
end
Upvotes: 2
Views: 1829
Reputation: 219
src="http://localhost:8080/images/missing.png"
move that to the public/images
folder
Upvotes: 0