2016-03-18 6 views
0

Ich möchte einige Avatare om meine Benutzer, aber nicht scheinen, Bilder aus dem öffentlichen Ordner zu liefern.Rails 4 - Serving ein Bild aus dem öffentlichen Ordner

es einfach zu machen ich eine Datei in

RAILS_ROOT/public/uploads/user/avatar/6/mh.jpg 

habe ich versuchen, es zu dienen mit:

%img{:src=>"/uploads/user/avatar/6/mh.jpg"} 

in meinem prowser wird es als gerenderte:

<img src="/uploads/user/avatar/6/mh.jpg"> 

die übersetzt in (denke ich):

http://localhost:3000/uploads/user/avatar/6/mh.jpg 

I enter image description here

Ich habe Berechtigungen für den Ordner überprüft. Ich habe die Folling Einstellung in development.rb schnippte:

config.serve_static_files = false 

Keine Änderung.

Meine Strecken sind - nach Rake Routen:

 Rails.application.routes.draw do 

     devise_for :users 

     concern :paginatable do 
     get '(page/:page)', :action => :index, :on => :collection, :as => '' 
     end 



     match 'albums/select' => 'albums/select', via: [:get, :post] 
     #get 'albums/show_stat' => 'albums#show_stat' 
     resources :albums, :concerns => :paginatable 


     match "photos/(year/:year)/(month/:month)/(day/:day)/(country/:country)" => "photos#index", :via => [:post, :get] 
     resources :photos, :except => [:create, :index] 
     get '/photos/:id/image/:size' => 'photos#image' 
     get '/photos/:id/display' => 'photos#display' 

     resources :catalogs 
     get '/catalogs/:id/dashboard' => 'catalogs#dashboard' 
     get '/catalogs/:id/get_catalog' => 'catalogs#get_catalog' 
     match "/catalogs/:id/edit" => "catalogs#edit", via: [:get, :post] 
     get "/catalogs/:id/destroy" => "catalogs#destroy" 
     get '/catalogs/authorize' => 'catalogs#authorize' 
     get '/catalogs/authorize_callback' => 'catalogs#authorize_callback' 

     #resources :localcatalogs, controller: 'catalogs', type: 'LocalCatalog', :concerns => :paginatable 
     match '/catalogs/:id/import' => 'catalogs#import', via: [:get, :post] 

     get '/locations/lookup' 
     resources :locations, :concerns => :paginatable 
     get '/locations/:id/view' => 'locations#view' 


     post 'bucket/:id/add' => 'bucket#add' 
     post 'bucket/:id/remove' => 'bucket#remove' 
     get 'bucket/list' => 'bucket#list' 
     get 'bucket' => 'bucket#index' 
     get 'bucket/clear' => 'bucket#clear' 
     get 'bucket/count' => 'bucket#count' 
     get 'bucket/save' => 'bucket#save_to_album' 
     get 'bucket/delete_photos' => 'bucket#delete_photos' 

     get 'doubles/find' 
     get 'doubles/index' 
     get 'doubles/:doubles_id/delete/:photo_id' => 'doubles#delete' 

     get 'administration/generate_albums' 
     get 'administration/jobs_pending' 
     get 'administration/list_jobs' 

     post 'jobs/list' => 'jobs#list' 
     resources :jobs 

     require 'resque/server' 
     mount Resque::Server.new, at: "/resque" 


     root to: 'photos#index' 

    end 

In meinem log ich:

 Started GET "/uploads/user/avatar/6/mh.jpg" for ::1 at 2016-03-18 22:38:07 +0100 

    ActionController::RoutingError (No route matches [GET] "/uploads/user/avatar/6/mh.jpg"): 
     actionpack (4.2.5) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' 
     web-console (2.3.0) lib/web_console/middleware.rb:28:in `block in call' 
     web-console (2.3.0) lib/web_console/middleware.rb:18:in `catch' 
     web-console (2.3.0) lib/web_console/middleware.rb:18:in `call' 
     actionpack (4.2.5) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' 
     railties (4.2.5) lib/rails/rack/logger.rb:38:in `call_app' 
     railties (4.2.5) lib/rails/rack/logger.rb:20:in `block in call' 
     activesupport (4.2.5) lib/active_support/tagged_logging.rb:68:in `block in tagged' 
     activesupport (4.2.5) lib/active_support/tagged_logging.rb:26:in `tagged' 
     activesupport (4.2.5) lib/active_support/tagged_logging.rb:68:in `tagged' 
     railties (4.2.5) lib/rails/rack/logger.rb:20:in `call' 
     actionpack (4.2.5) lib/action_dispatch/middleware/request_id.rb:21:in `call' 
     rack (1.6.4) lib/rack/methodoverride.rb:22:in `call' 
     rack (1.6.4) lib/rack/runtime.rb:18:in `call' 
     activesupport (4.2.5) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call' 
+0

Haben Sie es ohne den ersten Schrägstrich versucht? 'uploads/..' statt '/ uploads/...' – SteveTurczyn

+0

Ja, ich habe. Keine Änderung ... ohne das '/' wird dem Pfad das Modell vorangestellt, welches 'Benutzer' ist – martin

Antwort

0

es gelöst ... es war dieser Typ:

config.serve_static_files = false 

wenn ich es auf true ändere, habe ich vergessen, den Server neu zu starten .... verbrachte Stunden cos davon: - |

Verwandte Themen