Get view information for current route via Rails console

92 views Asked by At

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?

1

There are 1 answers

1
Sercan Tırnavalı On

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)