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

  • Home
  • SEARCH
  • 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 8459901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:27:24+00:00 2026-06-10T13:27:24+00:00

By default, Rails can find views with the format, locale and template language in

  • 0

By default, Rails can find views with the format, locale and template language in the filename (so I can create index.de.json.erb)

Is it possible to add another, custom parameter to the view’s filename?

I would like to pass the current subdomain, so http://foo.example.com/ would render index.foo.html.erb, and http://bar.example.com/ would render index.bar.html.erb (both of them with index.html.erb fallback).

  • 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-06-10T13:27:26+00:00Added an answer on June 10, 2026 at 1:27 pm

    The resolving pattern that is used to look up views can only contain variables that are registered with the ActionView::LookupContext class. The first step is therefore to register a new variable (subdomain) with the LookupContext class. You should do this in an initializer:

    ActionView::LookupContext.register_detail(:subdomain) do
      ['default_subdomain']
    end
    

    Now the LookupContext knows about the subdomain, it can be included in the resolving pattern. For more detail about changing the resolving pattern, see the ActionView::FileSystemResolver documentation, but essentially you should include the following, also in an initializer:

    ActionController::Base.view_paths = ActionView::FileSystemResolver.new(
      Rails.root.join('app', 'views'),
      ':prefix/:action{.:locale,}{.:subdomain,}{.:formats,}{.:handlers,}'
    )
    

    This pattern is eventually passed to Dir.glob (after the :* variables have been replaced). The glob pattern {.:subdomain,} means “either .:subdomain or nothing”, which provides the fallback to a view file with no subdomain if the file with a subdomain isn’t found.

    The final step is to update your ApplicationController to pass the subdomain to the LookupContext:

    class ApplicationController < ActionController::Base
      def details_for_lookup
        {:subdomain => [request.subdomain]}
      end
    end
    

    (This answer was mostly figured out by reading source code, some of these features aren’t documented. It was tested with Rails 3.2.5)

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

Sidebar

Related Questions

In Rails (and even in Doctrine < 2, IIRC) you can specify a default
If I want to change the default controller template created by scaffold in Rails
In section 5.1 of the tutorial, Rails can't seem to find the CSS file
In a new Rails 3.2 app you can find in config/initializers/wrap_parameters.rb the following lines:
I know rails uses the default application.html.erb. I have a profile and on my
I thought methods such as name and email were default in rails? In my
The default in Ruby on Rails is to have this set to false (in
I know rails provided CSRF protection by default from rails3. but my web application
In Rails 3.2 I'm trying to set a default OdontologicUnity instace when a User
By default the form post CSRF protection in Rails creates an authenticity token for

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.