2016-03-18 3 views
0

私はいくつかのアバターをユーザから取得したいが、パブリックフォルダから画像を提供することはできない。Rails 4 - パブリックフォルダの画像を提供する

私は私がそれを提供しようと

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

内のファイル持って、それを簡単にする:

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

:それは次のようにレンダリングされた私のprowserに

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

を(私は思う)に翻訳する:

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

私はenter image description here

私は、フォルダのアクセス許可を確認しています。 私はdevelopment.rbでfolling設定をいじっています

config.serve_static_files = false 

変更なし。

私のルートがある - すくい経路に従って:私のログで

 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 

私が手:

 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

最初のスラッシュなしで試しましたか? '/ uploads/... 'の代わりに' uploads/.. 'を使います。 – SteveTurczyn

+0

はい私は持っています。変更なし... '/'を除いたパスにはモデルの接頭辞が付きます。これは 'users' – martin

答えて

0

が、それはこの男だった...それを解決:

config.serve_static_files = false 

それをtrueに変更すると、私はサーバを再起動するのを忘れました....これの時間を費やしました: - |

関連する問題