路由在开发中有效,但在生产中无效
Routes work in Development But not in Production
奇怪的错误。我有一些在开发过程中完美运行的路由,但是一旦我部署并尝试访问它们,它就会出现页面不存在错误
我有以下 routes.rb 文件:
TransportUnl::Application.routes.draw do
resources :trucks
resources :shipments do
collection do
get :autocomplete_location_cs
end
end
devise_for :users do
get '/users/sign_in' => 'devise/sessions#new'
get '/users/sign_out' => 'devise/sessions#destroy'
end
root :to => 'info#index'
resources :info do
collection do
get 'about'
get 'contact'
get 'you_dont_have_a_full_account'
get 'help'
end
member do
get 'index'
end
end
resources :companies
end
尚未设置所有内容。但是当我转到:
时出现页面未找到错误
www.website.com/shipments
www.website.com/trucks
以及生产中的其他人。主索引页面有效,您可以登录,但找不到这些页面。
生产
发展
Production.log
Started GET "/shipments" for 108.235.52.160 at 2015-06-22 13:09:03 -0500
Processing by ShipmentsController#index as HTML
[1m[35m (0.6ms)[0m SELECT MAX("shipments"."price") AS max_id FROM "shipments"
[1m[36mShipment Load (0.3ms)[0m [1mSELECT "shipments".* FROM "shipments" [0m
Rendered shipments/_nav.html.erb (0.6ms)
Rendered shipments/_search_table.html.erb (0.1ms)
Rendered shipments/index.html.erb within layouts/application (1.2ms)
[1m[35mUser Load (0.5ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Rendered shared/_header.html.erb (5.0ms)
Completed 500 Internal Server Error in 12ms
ActionController::RoutingError (No route matches {:action=>"edit", :controller=>"companies"}):
app/views/shared/_header.html.erb:78:in `_app_views_shared__header_html_erb___2847381188393053217_232073740'
app/views/layouts/application.html.erb:17:in `_app_views_layouts_application_html_erb__4421904906041360553_230384600'
app/controllers/shipments_controller.rb:7:in `index'
Started GET "/info/about" for 157.55.39.229 at 2015-06-22 13:10:29 -0500
Processing by InfoController#about as */*
Rendered info/about.html.erb within layouts/application (5.7ms)
Rendered shared/_header.html.erb (3.8ms)
[1m[36m (4.3ms)[0m [1mSELECT * FROM geometry_columns WHERE f_table_name='shipments'[0m
[1m[35mShipment Load (0.9ms)[0m SELECT "shipments".* FROM "shipments" ORDER BY id DESC LIMIT 3
Rendered shared/_footer.html.erb (31.6ms)
Completed 200 OK in 177ms (Views: 151.1ms | ActiveRecord: 25.6ms)
Link 是这样创建的:
<%= link_to "My Account", edit_company_path(current_user.company_id) %>
从日志中可以看出,由于 app/views/shared/_header.html.erb
文件的第 78 行,您得到了错误页面。
在这段代码中,您创建 link
<%= link_to "My Account", edit_company_path(current_user.company_id) %>
检查 company_id 对于该特定用户是否不为零。我很确定你的情况是零。
正如您从错误日志中看到的那样,它试图将操作编辑作为公司控制器的收集操作 - companies/edit
。您没有定义这条路线。但是如果当前用户有 company_id,link 将被正确构建并且您不会收到错误。
奇怪的错误。我有一些在开发过程中完美运行的路由,但是一旦我部署并尝试访问它们,它就会出现页面不存在错误
我有以下 routes.rb 文件:
TransportUnl::Application.routes.draw do
resources :trucks
resources :shipments do
collection do
get :autocomplete_location_cs
end
end
devise_for :users do
get '/users/sign_in' => 'devise/sessions#new'
get '/users/sign_out' => 'devise/sessions#destroy'
end
root :to => 'info#index'
resources :info do
collection do
get 'about'
get 'contact'
get 'you_dont_have_a_full_account'
get 'help'
end
member do
get 'index'
end
end
resources :companies
end
尚未设置所有内容。但是当我转到:
时出现页面未找到错误www.website.com/shipments
www.website.com/trucks
以及生产中的其他人。主索引页面有效,您可以登录,但找不到这些页面。
生产
发展
Production.log
Started GET "/shipments" for 108.235.52.160 at 2015-06-22 13:09:03 -0500
Processing by ShipmentsController#index as HTML
[1m[35m (0.6ms)[0m SELECT MAX("shipments"."price") AS max_id FROM "shipments"
[1m[36mShipment Load (0.3ms)[0m [1mSELECT "shipments".* FROM "shipments" [0m
Rendered shipments/_nav.html.erb (0.6ms)
Rendered shipments/_search_table.html.erb (0.1ms)
Rendered shipments/index.html.erb within layouts/application (1.2ms)
[1m[35mUser Load (0.5ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Rendered shared/_header.html.erb (5.0ms)
Completed 500 Internal Server Error in 12ms
ActionController::RoutingError (No route matches {:action=>"edit", :controller=>"companies"}):
app/views/shared/_header.html.erb:78:in `_app_views_shared__header_html_erb___2847381188393053217_232073740'
app/views/layouts/application.html.erb:17:in `_app_views_layouts_application_html_erb__4421904906041360553_230384600'
app/controllers/shipments_controller.rb:7:in `index'
Started GET "/info/about" for 157.55.39.229 at 2015-06-22 13:10:29 -0500
Processing by InfoController#about as */*
Rendered info/about.html.erb within layouts/application (5.7ms)
Rendered shared/_header.html.erb (3.8ms)
[1m[36m (4.3ms)[0m [1mSELECT * FROM geometry_columns WHERE f_table_name='shipments'[0m
[1m[35mShipment Load (0.9ms)[0m SELECT "shipments".* FROM "shipments" ORDER BY id DESC LIMIT 3
Rendered shared/_footer.html.erb (31.6ms)
Completed 200 OK in 177ms (Views: 151.1ms | ActiveRecord: 25.6ms)
Link 是这样创建的:
<%= link_to "My Account", edit_company_path(current_user.company_id) %>
从日志中可以看出,由于 app/views/shared/_header.html.erb
文件的第 78 行,您得到了错误页面。
在这段代码中,您创建 link
<%= link_to "My Account", edit_company_path(current_user.company_id) %>
检查 company_id 对于该特定用户是否不为零。我很确定你的情况是零。
正如您从错误日志中看到的那样,它试图将操作编辑作为公司控制器的收集操作 - companies/edit
。您没有定义这条路线。但是如果当前用户有 company_id,link 将被正确构建并且您不会收到错误。