我的 Rails 4 应用程序的生产服务器上记录了一个奇怪的错误:
ActionController::RoutingError: No route matches [GET] "/sign_up"
这显然令人担忧,因为这意味着新用户无法注册。但是,如果我通过手动输入或单击我们主页上的按钮访问该 URL,我可以看到注册页面。
没有重定向,URL 栏中的 URL 保持不变。
这是有问题的路线:
devise_scope :identity do
get 'sign_in', :to => 'devise/sessions#new'
get 'sign_up', :to => 'devise/registrations#new'
get 'sign_out', :to => 'devise/sessions#destroy'
end
由于主题 hack,我们主页上的按钮是一个使用 GET 提交的表单。我认为这可能是一个问题,但日志显示它正在正确接收 GET 请求。
这里发生了什么?我应该从哪里开始寻找诊断?
更新
通过我们主页上的黑客攻击,我的意思是,由于<a class="btn...
导航栏中不支持引导程序,我们使用带有方法 GET 的表单来使用它支持的那种按钮 - 所以从服务器的角度来看,用户仍在发送GET /sign_up 当他们单击该按钮时。这个按钮只是为了让他们进入 /sign_up 页面(registration_controller#new),而不是他们用来提交包含所有详细信息的注册表单的按钮。
(注册表单本身是正常的,即它发送一个 POST)
需要明确的是,我已经手动完成了完整的注册过程,并且它有效。我从来没有收到 404。当我进行遍历时,日志消息不会出现。
以下是相关部分rake routes
Prefix Verb URI Pattern Controller#Action
new_identity_session GET /identities/sign_in(.:format) devise/sessions#new
identity_session POST /identities/sign_in(.:format) devise/sessions#create
destroy_identity_session DELETE /identities/sign_out(.:format) devise/sessions#destroy
cancel_identity_registration GET /identities/cancel(.:format) identities/registrations#cancel
identity_registration POST /identities(.:format) identities/registrations#create
new_identity_registration GET /identities/sign_up(.:format) identities/registrations#new
edit_identity_registration GET /identities/edit(.:format) identities/registrations#edit
PATCH /identities(.:format) identities/registrations#update
PUT /identities(.:format) identities/registrations#update
DELETE /identities(.:format) identities/registrations#destroy
sign_in GET /sign_in(.:format) devise/sessions#new
sign_up GET /sign_up(.:format) devise/registrations#new
sign_out GET /sign_out(.:format) devise/sessions#destroy
更新 2
我们仍在生产服务器上记录此问题。错误来自滚动条。有趣的是,它没有出现在我们的生产日志中。生产日志使用单行日志记录。我们无法在开发中重现它,这是访问该页面的日志:
Started GET "/sign_up" for 127.0.0.1 at 2017-01-02 12:25:10 +0800
Processing by Devise::RegistrationsController#new as HTML
Rendered identities/shared/_sign_up.html.erb (203.5ms)
Rendered identities/registrations/new.html.erb within layouts/focused (277.2ms)
Rendered layouts/_social_headers.html.erb (39.1ms)
Rendered layouts/_google_analytics.html.erb (6.2ms)
Rendered layouts/_scripts.html.erb (3618.9ms)
Rendered layouts/_hotjar.html.erb (4.7ms)
Rendered layouts/_html_head.html.erb (3708.2ms)
Nation Load (4.5ms) SELECT "nations".* FROM "nations" WHERE "nations"."id" IS NULL ORDER BY "nations"."id" ASC LIMIT 1
Rendered layouts/_topnavbar.html.erb (101.0ms)
Rendered layouts/_breadcrumb.html.erb (7.4ms)
Rendered layouts/_flash.html.erb (31.4ms)
Rendered layouts/_footer2.html.erb (8.6ms)
Completed 200 OK in 4223ms (Views: 4203.2ms | ActiveRecord: 4.5ms)