Can I get the name of the current controller in the view?

后端 未结 5 1735
误落风尘
误落风尘 2020-11-29 16:17

Is there a way to figure out what the current controller is from within the view?

For an example of why I would want to know this: if several controllers share the s

5条回答
  •  野性不改
    2020-11-29 17:01

    If you want to use all stylesheet in your app just adds this line in application.html.erb. Insert it inside tag

      <%= stylesheet_link_tag  controller.controller_name , media: 'all', 'data-turbolinks-track': 'reload' %>
    

    Also, to specify the same class CSS on a different controller
    Add this line in the body of application.html.erb

      
    

    So, now for example I would like to change the p tag in 'home' controller and 'index' action. Inside index.scss file adds.

    .nameOfController-nameOfAction  { }
    

     .home-index p {
            color:red !important;
          }
    

提交回复
热议问题