root_path get方法的Rails问题

时间:2017-02-06 14:34:03

标签: ruby-on-rails devise routing

感谢您的专家建议。如果这个问题不合适或者不合适,请发表评论或邮寄给我,我会将其删除。

我正在构建一个使用两个不同布局的Ruby on Rails应用程序。第一页是设置为应用程序根目录的介绍页面,新用户可以在其中显示有关应用程序的一些基本信息,然后登录或注册。

第一页有完美的布局 main.html.erb 视图 main / welcome.html.erb

当用户单击“注册”链接时,将调用“注册”的设计视图。

<%= link_to "Sign Up", new_account_registration_path  %>

由于Application Controller具有第二个用户布局,它会毫无问题地显示此布局中的所有视图。

class ApplicationController < ActionController::Base
    layout "user"

    protect_from_forgery with: :exception
end

在视图 registration / new 中,我有另一个链接,允许用户取消注册并返回应用程序的主页和根目录(呈现布局 main.html.erb 视图 main / welcome.html.erb )。

如果我使用方法的根路径:: get ,根页面将加载而不会有任何问题。 布局视图都会加载。

<%= link_to "Cancel", root_path, method: :get, :class => "btn btn-default wideButton" %>

如果我在没有get方法的情况下使用root_path,则不会加载某些内容。 这是结果:

this case

首页将加载,但仅限于导航栏,而其他HTML内容将无法加载。

在我使用的情况下:method =&gt; :get,页面有效,这就是结果。 主要区别在于,在第一种情况下(不工作)有一个get请求,而在第二种情况下(页面加载)浏览器显示一个发送请求到/.

enter image description here

这是非工作方案的日志。另外我会问在这种不调用cancel_account_registration_path的情况下有什么风险。

非常感谢。 最好的祝福 Fabrizio Bertoglio

=> Booting Puma
=> Rails 5.0.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.6.2 (ruby 2.3.3-p222), codename: Sleepy Sunday Serenity
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop
2017-02-06 15:03:37.531 [fyi] Started GET "/account/sign_up" for 127.0.0.1 at 2017-02-06 15:03:37 +0100 (pid:9730)
2017-02-06 15:03:37.548 [meh] ActiveRecord::SchemaMigration Load (0.3ms)  SELECT `schema_migrations`.* FROM `schema_migrations` (pid:9730)
2017-02-06 15:03:37.570 [fyi] Processing by Account::RegistrationsController#new as HTML (pid:9730)
2017-02-06 15:03:37.600 [fyi] Rendering account/registrations/new.html.erb within layouts/user (pid:9730)
2017-02-06 15:03:37.605 [fyi] Rendered partials/_error_messages.html.erb (0.6ms) (pid:9730)
2017-02-06 15:03:37.643 [fyi] Rendered account/registrations/new.html.erb within layouts/user (42.8ms) (pid:9730)
2017-02-06 15:03:37.982 [fyi] Completed 200 OK in 411ms (Views: 386.4ms | ActiveRecord: 1.2ms) (pid:9730)
2017-02-06 15:03:40.211 [fyi] Started GET "/" for 127.0.0.1 at 2017-02-06 15:03:40 +0100 (pid:9730)
2017-02-06 15:03:40.213 [fyi] Processing by MainController#welcome as HTML (pid:9730)
2017-02-06 15:03:40.215 [fyi] Rendering main/welcome.html.erb within layouts/main (pid:9730)
2017-02-06 15:03:40.217 [fyi] Rendered main/welcome.html.erb within layouts/main (1.5ms) (pid:9730)
2017-02-06 15:03:40.280 [fyi] Completed 200 OK in 67ms (Views: 65.6ms | ActiveRecord: 0.0ms) (pid:9730)

这是工作功能的日志。

>> rails server
=> Booting Puma
=> Rails 5.0.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.6.2 (ruby 2.3.3-p222), codename: Sleepy Sunday Serenity
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop
2017-02-06 15:12:00.775 [fyi] Started GET "/account/sign_up" for 127.0.0.1 at 2017-02-06 15:12:00 +0100 (pid:9893)
2017-02-06 15:12:00.796 [meh] ActiveRecord::SchemaMigration Load (0.3ms)  SELECT `schema_migrations`.* FROM `schema_migrations` (pid:9893)
2017-02-06 15:12:00.825 [fyi] Processing by Account::RegistrationsController#new as HTML (pid:9893)
2017-02-06 15:12:00.859 [fyi] Rendering account/registrations/new.html.erb within layouts/user (pid:9893)
2017-02-06 15:12:00.863 [fyi] Rendered partials/_error_messages.html.erb (0.6ms) (pid:9893)
2017-02-06 15:12:00.908 [fyi] Rendered account/registrations/new.html.erb within layouts/user (49.0ms) (pid:9893)
2017-02-06 15:12:01.242 [fyi] Completed 200 OK in 416ms (Views: 386.2ms | ActiveRecord: 1.1ms) (pid:9893)
2017-02-06 15:12:04.500 [fyi] Started GET "/" for 127.0.0.1 at 2017-02-06 15:12:04 +0100 (pid:9893)
2017-02-06 15:12:04.503 [fyi] Processing by MainController#welcome as HTML (pid:9893)
2017-02-06 15:12:04.503 [fyi] Parameters: {"authenticity_token"=>"n52C8V3Z6S8FrACAWJeU+IIAfBy2N/7rWIV+338pDTBHmvCQq0JvKOA9zhEgvy7IgGIPvexP3Du8db10lm9AVA=="} (pid:9893)
2017-02-06 15:12:04.505 [fyi] Rendering main/welcome.html.erb within layouts/main (pid:9893)
2017-02-06 15:12:04.508 [fyi] Rendered main/welcome.html.erb within layouts/main (2.1ms) (pid:9893)
2017-02-06 15:12:04.539 [fyi] Started GET "/" for 127.0.0.1 at 2017-02-06 15:12:04 +0100 (pid:9893)
2017-02-06 15:12:04.547 [fyi] Processing by MainController#welcome as HTML (pid:9893)
2017-02-06 15:12:04.550 [fyi] Parameters: {"authenticity_token"=>"n52C8V3Z6S8FrACAWJeU+IIAfBy2N/7rWIV+338pDTBHmvCQq0JvKOA9zhEgvy7IgGIPvexP3Du8db10lm9AVA=="} (pid:9893)
2017-02-06 15:12:04.569 [fyi] Rendering main/welcome.html.erb within layouts/main (pid:9893)
2017-02-06 15:12:04.575 [fyi] Rendered main/welcome.html.erb within layouts/main (1.1ms) (pid:9893)
2017-02-06 15:12:04.597 [fyi] Completed 200 OK in 94ms (Views: 92.5ms | ActiveRecord: 0.0ms) (pid:9893)
2017-02-06 15:12:04.639 [fyi] Completed 200 OK in 77ms (Views: 73.5ms | ActiveRecord: 0.0ms) (pid:9893)

0 个答案:

没有答案