Rails 3.2.13
我基本上是尝试使用此截屏视频进行部署:http://railscasts.com/episodes/335-deploying-to-a-vps
我有一个可以在开发中使用的应用程序,但是当使用Capistrano推送到生产时,我的一个控制器操作几乎全部产生404页。
当我运行'rake routes'时,我注意到输出中缺少此控制器的操作:
的routes.rb
Wagmantechnology::Application.routes.draw do
root :to => 'static_pages#home'
resources :users
resources :sessions, only: [:new, :create, :destroy]
resources :tasks
resources :assets
match '/signup', to: 'users#new'
match '/signin', to: 'sessions#new'
match '/signout', to: 'sessions#destroy', via: :delete
match 'tasks/mjhartman' => "tasks#mjhartman", :as => "tasks_mjhartman"
match 'tasks/ejmcfadden' => "tasks#ejmcfadden", :as => "tasks_ejmcfadden"
match 'tasks/ctkahler' => "tasks#ctkahler", :as => "tasks_ctkahler"
match 'tasks/gafc' => "tasks#gafc", :as => "tasks_gafc"
match 'tasks/wci' => "tasks#wci", :as => "tasks_wci"
match 'tasks/fsc' => "tasks#fsc", :as => "tasks_fsc"
match 'tasks/wagco' => "tasks#wagco", :as => "tasks_wagco"
match 'tasks/it' => "tasks#it", :as => "tasks_it"
match 'tasks/atf' => "tasks#atf", :as => "tasks_atf"
match 'tasks/hr' => "tasks#hr", :as => "tasks_hr"
match 'tasks/legal' => "tasks#legal", :as => "tasks_legal"
match 'tasks/marketing' => "tasks#marketing", :as => "tasks_marketing"
match 'tasks/user_request' => "tasks#user_request", :as => "tasks_user_request"
match 'tasks/jde' => "tasks#jde", :as => "tasks_jde"
match 'tasks/communications' => "tasks#communications", :as => "tasks_communications"
match 'tasks/hardware' => "tasks#hardware", :as => "tasks_hardware"
match 'tasks/software' => "tasks#software", :as => "tasks_software"
match 'tasks/documentation' => "tasks#documentation", :as => "tasks_documentation"
match 'tasks/security' => "tasks#security", :as => "tasks_security"
match 'tasks/billing' => "tasks#billing", :as => "tasks_billing"
match 'tasks/training' => "tasks#training", :as => "tasks_training"
match 'tasks/york_gafc' => "tasks#york_gafc", :as => "tasks_york_gafc"
match 'tasks/york_wci' => "tasks#york_wci", :as => "tasks_york_wci"
match 'tasks/berryville' => "tasks#berryville", :as => "tasks_berryville"
match 'tasks/route52' => "tasks#route52", :as => "tasks_route52"
match 'tasks/gafc_field' => "tasks#gafc_field", :as => "tasks_gafc_field"
match 'tasks/wci_field' => "tasks#wci_field", :as => "tasks_wci_field"
match 'assets/laptop' => "assets#laptop", :as => "assets_laptop"
match 'assets/desktop' => "assets#desktop", :as => "assets_desktop"
match 'assets/server' => "assets#server", :as => "assets_server"
match 'assets/network' => "assets#network", :as => "assets_network"
match 'assets/tablet' => "assets#tablet", :as => "assets_tablet"
match 'assets/cell' => "assets#cell", :as => "assets_cell"
match 'assets/data' => "assets#data", :as => "assets_data"
match 'assets/office' => "assets#office", :as => "assets_office"
match 'assets/printer' => "assets#printer", :as => "assets_printer"
match 'assets/gafc' => "assets#gafc", :as => "assets_gafc"
match 'assets/wci' => "assets#wci", :as => "assets_wci"
match 'assets/fsc' => "assets#fsc", :as => "assets_fsc"
match 'assets/wagco' => "assets#wagco", :as => "assets_wagco"
match 'assets/it' => "assets#it", :as => "assets_it"
match 'assets/atf' => "assets#atf", :as => "assets_atf"
match 'assets/hr' => "assets#hr", :as => "assets_hr"
match 'assets/legal' => "assets#legal", :as => "assets_legal"
match 'assets/marketing' => "assets#marketing", :as => "assets_marketing"
match 'assets/user_request' => "assets#user_request", :as => "assets_user_request"
match 'assets/jde' => "assets#jde", :as => "assets_jde"
match 'assets/communications' => "assets#communications", :as => "assets_communications"
match 'assets/hardware' => "assets#hardware", :as => "assets_hardware"
match 'assets/software' => "assets#software", :as => "assets_software"
match 'assets/documentation' => "assets#documentation", :as => "assets_documentation"
match 'assets/security' => "assets#security", :as => "assets_security"
match 'assets/billing' => "assets#billing", :as => "assets_billing"
match 'assets/training' => "assets#training", :as => "assets_training"
match 'assets/york_gafc' => "assets#york_gafc", :as => "assets_york_gafc"
match 'assets/york_wci' => "assets#york_wci", :as => "assets_york_wci"
match 'assets/berryville' => "assets#berryville", :as => "assets_berryville"
match 'assets/route52' => "assets#route52", :as => "assets_route52"
match 'assets/gafc_field' => "assets#gafc_field", :as => "assets_gafc_field"
match 'assets/wci_field' => "assets#wci_field", :as => "assets_wci_field"
match 'assets/inventory' => "assets#inventory", :as => "assets_inventory"
end
'rake routes'的输出:
root / static_pages#home
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
sessions POST /sessions(.:format) sessions#create
new_session GET /sessions/new(.:format) sessions#new
session DELETE /sessions/:id(.:format) sessions#destroy
tasks GET /tasks(.:format) tasks#index
POST /tasks(.:format) tasks#create
new_task GET /tasks/new(.:format) tasks#new
edit_task GET /tasks/:id/edit(.:format) tasks#edit
task GET /tasks/:id(.:format) tasks#show
PUT /tasks/:id(.:format) tasks#update
DELETE /tasks/:id(.:format) tasks#destroy
signup /signup(.:format) users#new
signin /signin(.:format) sessions#new
signout DELETE /signout(.:format) sessions#destroy
tasks_mjhartman /tasks/mjhartman(.:format) tasks#mjhartman
tasks_ejmcfadden /tasks/ejmcfadden(.:format) tasks#ejmcfadden
tasks_ctkahler /tasks/ctkahler(.:format) tasks#ctkahler
tasks_gafc /tasks/gafc(.:format) tasks#gafc
tasks_wci /tasks/wci(.:format) tasks#wci
tasks_fsc /tasks/fsc(.:format) tasks#fsc
tasks_wagco /tasks/wagco(.:format) tasks#wagco
tasks_it /tasks/it(.:format) tasks#it
tasks_atf /tasks/atf(.:format) tasks#atf
tasks_hr /tasks/hr(.:format) tasks#hr
tasks_legal /tasks/legal(.:format) tasks#legal
tasks_marketing /tasks/marketing(.:format) tasks#marketing
tasks_user_request /tasks/user_request(.:format) tasks#user_request
tasks_jde /tasks/jde(.:format) tasks#jde
tasks_communications /tasks/communications(.:format) tasks#communications
tasks_hardware /tasks/hardware(.:format) tasks#hardware
tasks_software /tasks/software(.:format) tasks#software
tasks_documentation /tasks/documentation(.:format) tasks#documentation
tasks_security /tasks/security(.:format) tasks#security
tasks_billing /tasks/billing(.:format) tasks#billing
tasks_training /tasks/training(.:format) tasks#training
tasks_york_gafc /tasks/york_gafc(.:format) tasks#york_gafc
tasks_york_wci /tasks/york_wci(.:format) tasks#york_wci
tasks_berryville /tasks/berryville(.:format) tasks#berryville
tasks_route52 /tasks/route52(.:format) tasks#route52
tasks_gafc_field /tasks/gafc_field(.:format) tasks#gafc_field
tasks_wci_field /tasks/wci_field(.:format) tasks#wci_field
您会看到没有列出任何资产路线。为什么?奇怪的是,索引动作/资产在生产中起作用,但没有别的。所有链接都在开发中。我在这里做错了什么?
答案 0 :(得分:2)
原因应该是名称与资产管道冲突。
路由中的“资产”一词过于敏感,与Rails静态资产相同。您可以验证localhost:3000/assets/rails.png
是否可以在开发环境中运行,但不能生成。所有“资产”路线都已在生产模式中更改。
我的建议是将您的路由名称空间从“assets”重命名为其他名称。但这可能涉及很多工作。我还不知道其他更简单的方法。
<强>更新强> 感谢@ sevenseacat的评论。他指出了一种更简单的方法 - 改变资产路线
config.assets.prefix = "/some_other_path"
参考:资产路径“&gt; http://guides.rubyonrails.org/asset_pipeline.html#changing-the- 资产 -path