Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 847885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:51:31+00:00 2026-05-15T06:51:31+00:00

I can do request.path_parameters[‘controller’] and request.path_parameters[‘action’], but is there anything like request.path_parameters[‘template’] so I

  • 0

I can do request.path_parameters[‘controller’] and request.path_parameters[‘action’], but is there anything like request.path_parameters[‘template’] so I can discern which template file (such as index.html.erb) is being rendered?

I’m writing a method that automatically sets the body id to the template being rendered, for easy css manipulation:

  class ApplicationController < ActionController::Base
  ...
  after_filter :define_body_selector
  ...
  def define_body_selector
    # sets @body_id to the name of the template that will be rendered
    # ie. if users/index.html.erb was just rendered, @body_id gets set to "index"
    @body_id = ???
  end
  ...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:51:32+00:00Added an answer on May 15, 2026 at 6:51 am

    If you have different template files you could use content_for in them (check out guide about layouts and templates) to set id in layout file, or just stick to params[:action] (it should be enough — choice of template is based on action called).

    You can make universal before_filter for all (or not all) actions with

    before_filter :set_id_for_body, :only => [...]
    
    def set_id_for_body
      @body_id = params[:action]
    end
    

    Always think how to keep your code DRY!


    EDIT:

    You could define hash that will link actions with matching templates:

    ActionClasses = { 
      :update => "show",
      :show   => "show,
      :new    => "new",
      :edit   => "new",
      ... 
    }
    

    Within your layout file just add

    <body id="<%= ActionClasses[params[:action]] %>">
    

    EDIT:

    It is possible to access template via ActionBase::template method, but it won’t work the way you would like it to. If you call filename or name method in layout file, you will get path to layout file, not template. AFAIK It is impossible to check what template is being rendered, as multiple of them can be used to render single action.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in websql we can request a certain row like this: tx.executeSql('SELECT * FROM tblSettings
I know I can use Request.Browser.IsMobileDevice . But does anyone know how it works,
I know we can request xml, html as well as text images directly using
Users on a website I'm building can request the availability of user names on
I've created a system where i can request an NSManagedObjectContext from a singleton object,
I am embedding a manifest in a .NET exe so that it can request
How can I send request to a URL: http://www.flashi.tv/embed.php?v=HitSportsNet41125 on port 80 with referrer
how can i use request.querystring in asp.net.i have a linkbutton and this is in
I have an Ajax request that can return more than one valid value, so
I have a web request that can take 30-90 seconds to complete in some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.