最近我注意到点击Devise的共享链接(例如forgot password?
和Didn't receive confirmation instructions?
)会导致页脚上的订阅者表单自动提交并最终在浏览器上抛出错误:
ActionController::UrlGenerationError in Devise::Passwords#new
No route matches {:action=>"subscribe", :controller=>"devise/home"}
并且控制台上的错误如下:
Started GET "/users/password/new" for ::1 at 2016-01-29 23:57:39 +0530
Processing by Devise::PasswordsController#new as HTML
Rendered devise/shared/_links.html.erb (1.1ms)
Rendered devise/passwords/new.html.erb within layouts/application (9.1ms)
Rendered layouts/_header.html.erb (6.7ms)
Rendered layouts/_messages.html.erb (0.6ms)
Rendered layouts/_footer.html.erb (5.0ms)
Completed 500 Internal Server Error in 588ms (ActiveRecord: 0.0ms)
ActionView::Template::Error (No route matches {:action=>"subscribe", :controller=>"devise/home"}):
31: </div><!--col-md-* end-->
32: <div class="col-md-4 mob-mgbtm-foo">
33: <div class="foo-hd">Subcribe to our Newsletter</div>
34: <%= form_tag({controller:"home", action: "subscribe"}, {class: 'form-inline'}) do %>
35: <div class="form-group">
36: <input name="email" type="email" class="foo-intxt form-control" placeholder="Your Email">
37: </div>
app/views/layouts/_footer.html.erb:34:in `_app_views_layouts__footer_html_erb___1185320491891532297_70313812020980'
app/views/layouts/application.html.erb:28:in `_app_views_layouts_application_html_erb___1232363268137916075_70313747392400'
Rendered /Users/abhinaykumar/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_source.erb (11.4ms)
Rendered /Users/abhinaykumar/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (3.6ms)
Rendered /Users/abhinaykumar/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.7ms)
Rendered /Users/abhinaykumar/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (145.6ms)
Rendered /Users/abhinaykumar/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/_markup.html.erb (0.7ms)
Rendered /Users/abhinaykumar/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.5ms)
Rendered /Users/abhinaykumar/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.4ms)
Rendered /Users/abhinaykumar/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/style.css.erb within layouts/inlined_string (1.2ms)
Rendered /Users/abhinaykumar/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/console.js.erb within layouts/javascript (72.0ms)
Rendered /Users/abhinaykumar/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/main.js.erb within layouts/javascript (0.5ms)
Rendered /Users/abhinaykumar/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.4ms)
Rendered /Users/abhinaykumar/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/index.html.erb (239.3ms)
Started GET "/users/password/new" for ::1 at 2016-01-29 23:57:41 +0530
Processing by Devise::PasswordsController#new as HTML
Rendered devise/shared/_links.html.erb (0.3ms)
Rendered devise/passwords/new.html.erb within layouts/application (6.4ms)
Rendered layouts/_header.html.erb (6.8ms)
Rendered layouts/_messages.html.erb (0.1ms)
Rendered layouts/_footer.html.erb (3.1ms)
Completed 500 Internal Server Error in 557ms (ActiveRecord: 0.0ms)
ActionView::Template::Error (No route matches {:action=>"subscribe", :controller=>"devise/home"}):
31: </div><!--col-md-* end-->
32: <div class="col-md-4 mob-mgbtm-foo">
33: <div class="foo-hd">Subcribe to our Newsletter</div>
34: <%= form_tag({controller:"home", action: "subscribe"}, {class: 'form-inline'}) do %>
35: <div class="form-group">
36: <input name="email" type="email" class="foo-intxt form-control" placeholder="Your Email">
37: </div>
app/views/layouts/_footer.html.erb:34:in `_app_views_layouts__footer_html_erb___1185320491891532297_70313813434860'
app/views/layouts/application.html.erb:28:in `_app_views_layouts_application_html_erb___1232363268137916075_70313747392400'
Rendered /Users/abhinaykumar/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_source.erb (10.8ms)
Rendered /Users/abhinaykumar/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (3.5ms)
Rendered /Users/abhinaykumar/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.9ms)
Rendered /Users/abhinaykumar/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (94.3ms)
Rendered /Users/abhinaykumar/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/_markup.html.erb (0.8ms)
Rendered /Users/abhinaykumar/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.6ms)
Rendered /Users/abhinaykumar/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.5ms)
Rendered /Users/abhinaykumar/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.5ms)
Rendered /Users/abhinaykumar/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/console.js.erb within layouts/javascript (86.8ms)
Rendered /Users/abhinaykumar/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/main.js.erb within layouts/javascript (0.4ms)
Rendered /Users/abhinaykumar/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.5ms)
Rendered /Users/abhinaykumar/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_console/templates/index.html.erb (188.4ms)
由于某些未知原因,点击forgot password?
正在重定向到devise/home
,如错误中所示。
此处是footer.html.erb
<%= form_tag({controller:"home", action: "subscribe"}, {class: 'form-inline'}) do %>
<div class="form-group">
<input name="email" type="email" class="foo-intxt form-control" placeholder="Your Email">
</div>
<button type="submit" class="org-btn btn">
<i class="fa fa-paper-plane"></i>
</button>
<% end %>
的routes.rb
devise_for :users, controllers: {registrations: :registrations, sessions: "sessions",
omniauth_callbacks: 'omniauth_callbacks'}
resources :guests
post 'subscribe', to: 'home#subscribe'
home_controller.rb
class HomeController < ApplicationController
# Home page
def index
end
def about
end
def subscribe
AdminMailer.subscribe(params[:email]).deliver_now
redirect_to root_path, notice: 'Thank you for Signing up for newsletter, will keep you posted!!'
end
def faq
end
end
另外,我不确定为什么错误会在终端上多次呈现。
答案 0 :(得分:1)
问题在于它试图使用页脚呈现忘记密码页面,但是当它试图在页脚中构建该链接时,它正在设计名称为home的控制器,该控制器不存在
有两种方法可以解决歧义:
<强> 1。使用命名路线
更改您的路线post 'subscribe', to: 'home#subscribe', as: :subscribe
,然后在您的表单中,尝试将其用于您的网址<%= form_tag(subscribe_path, ....
<强> 2。使用您当前的路线
或者,如果您不想为路线命名,可以尝试'/subscribe'
作为您的路线。