通过 Rails 控制台获取当前路线的查看信息

发布于 2025-01-15 20:17:20 字数 126 浏览 0 评论 0原文

我是里亚尔新手,我想通过 Rails 控制台找出特定路线正在使用哪个视图?

应用程序根据某些标准动态触发视图,并且此功能被我目前无法访问的 GEM 遮盖,因此尝试找出正在加载哪个视图(slim 或 erb)我目前所在的路线?

I'm new to Rials, and I'm trying to figure out which view is being used by a particular route, via the Rails console?

The application triggers view dynamically, based on certain criteria, and this functionality is obscured by a GEM which I don't have access to at this time, so trying to figure out which view (either a slim or an erb) is being loaded for the route I'm currently on?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一生独一 2025-01-22 20:17:20

打开项目文件夹上的终端并编写以下代码以查看具有相关控制器的所有路由。

rails routes

注意:此代码不应在 Rails 控制台中运行。

但是,如果您可以访问应用程序控制台,您可以看到如下所示的视图部分。

例如第 5 行的 _working_hours 是由 get 请求触发的部分内容。

Started GET "/transportation/index" for ::1 at 2022-03-21 14:15:47 +0300
Processing by TransportationController#index as HTML
  Rendering layout layouts/application.html.erb
  Rendering transportation/index.html.erb within layouts/application
  Rendered application/_working_hours.html.erb (Duration: 0.8ms | Allocations: 150)
  Rendered transportation/index.html.erb within layouts/application (Duration: 2.6ms | Allocations: 561)
  Rendered layout layouts/application.html.erb (Duration: 18.4ms | Allocations: 7734)
Completed 200 OK in 24ms (Views: 21.7ms | Allocations: 8699)

Open the terminal on the project folder and write the code below for see all routes with related controllers.

rails routes

Note: This code should not be run in rails console.

However if you can access application console you can see view partials like below.

For example _working_hours at 5th line, is a partial from triggered by get request.

Started GET "/transportation/index" for ::1 at 2022-03-21 14:15:47 +0300
Processing by TransportationController#index as HTML
  Rendering layout layouts/application.html.erb
  Rendering transportation/index.html.erb within layouts/application
  Rendered application/_working_hours.html.erb (Duration: 0.8ms | Allocations: 150)
  Rendered transportation/index.html.erb within layouts/application (Duration: 2.6ms | Allocations: 561)
  Rendered layout layouts/application.html.erb (Duration: 18.4ms | Allocations: 7734)
Completed 200 OK in 24ms (Views: 21.7ms | Allocations: 8699)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文