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 8094131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:41:54+00:00 2026-06-05T20:41:54+00:00

I am currently working through Michael Hartl’s Rails Tutorial while experimenting with some other

  • 0

I am currently working through Michael Hartl’s Rails Tutorial while experimenting with some other things not covered in the book. After completing Chapter 5, where the static pages are created, I decided change the view code to HAML, internationalize the pages, and put the static content into separate (non-partial) Markdown files, using the RDiscount gem to render them. For example:

app/views/static_pages/about.html.haml

- provide(:title, t('.about_us'))
:markdown
  #{render file: "static_pages/about.#{params[:locale]}.md"}

Under the static_pages directory, I have Markdown files like about.en.md, about.it.md, about.ja.md etc, so interpolating in the :locale parameter is what determines which language Markdown file gets rendered.

My questions are:

  1. The static_pages directory is a bit crowded with Markdown files, so are there any sensible default/best practice locations (perhaps outside of the app directory) to keep these Markdown files, where they could be presumably be edited by people who don’t need to know about the inner workings of the app?
  2. What better ways are there to implement rendering multi-lingual Markdown files in views? My use of :locale and the double string-interpolation seems inelegant.
  3. Is there a way to change this code so that I can pass Ruby variables into the Markdown file? I know I can, for example, use a #{language} variable in the Markdown by just changing about.en.md into a HAML partial (_about.en.html.haml) and change the code to look something like:

    app/views/static_pages/about.html.haml

    - provide(:title, t('.about_us'))
    :markdown
      #{render "about.#{params[:locale]}", language: 'Markdown!'}
    

    But, is there a way to do this without changing the Markdown file into another type of file? If such a way exists, is it recommended/feasible?

  • 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-05T20:41:55+00:00Added an answer on June 5, 2026 at 8:41 pm

    After having a look at this StackOverflow answer, it seemed that the best location for i18n Markdown files would be their own action name directories under the config/locales directory, and that there was a good opportunity to refactor the render code on all views for the StaticPagesController. So, using about.html.haml as an example below, the call to render in the home, help, about, and contact views has been changed to the exact same code:

    app/views/static_pages/about.html.haml

    - provide(:title, t('.about_us'))
    :markdown
      #{render file: localized_page_for(action_name, params[:locale])}
    

    The localized_page_for method is defined in the StaticPagesHelper:

    app/helpers/static_pages_helper.rb

    module StaticPagesHelper
      def localized_page_for(action, locale)
        "#{Rails.root}/config/locales/#{action}/#{action}.#{locale.to_s}.md"
      end
    end
    

    So, now all the Markdown files have been taken out of the app/views/static_pages directory and are called from their respective logical directories (eg. config/locales/about/about.en.md etc) using ActionController‘s action_name attribute and the locale, making for less clutter.

    As for question 2 above, string-interpolation seems to be common enough for this kind of problem, so I’ll consider it “elegant” enough as well.

    As for question 3 above, after exhaustive searching, I haven’t found a way anyone has passed in variables in to a pure Markdown file, and the documentation doesn’t seem to say anything about supporting them, so I’m going to conclude that it’s not possible. If passing Ruby variables in to Markdown is absolutely necessary, the file will need to be run through another interpreter, kind of like is described in this StackOverflow answer.

    Update:

    After running security scanner Brakeman against the app, it came up with a potential Dynamic Render Path security warning (albeit a weak one) due to dynamically passing in params[:locale] to the render call instead of passing it a static string. So, I moved the call to the localized_page method out of the views, moved the method itself out of the StaticPagesHelper (so that file is now empty) and in to the StaticPagesController and then instantiated a @page instance variable in each method to pass to the view. In summary, the code now looks like this, which doesn’t get the security warning:

    app/controllers/static_pages_controller.rb

    class StaticPagesController < ApplicationController
    
      before_filter :localized_page, only: [:help, :about, :contact]
    
      def home
        if signed_in?
          @micropost  = current_user.microposts.build
          @feed_items = current_user.feed.paginate(page: params[:page])
        else
          localized_page
        end
      end
    
     def help
     end
    
     def about
     end
    
     def contact  
     end
    
     private
    
       def localized_page
        @page = "#{Rails.root}/config/locales/"\
                "#{action_name}/#{action_name}.#{params[:locale].to_s}.md"
       end
    end
    

    app/views/static_pages/about.html.haml

    - provide(:title, t('.about_us'))
    :markdown
      #{render file: @page}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working through Michael Hartl's Ruby on Rails tutorial on http://ruby.railstutorial.org . I'm having
I am currently working through this tutorial: Getting Started with jQuery For the two
I'm currently working through some exercises in a c++ book, which uses text based
Currently working through a Teach Yourself WPF tutorial. Usually I can mentally convert from
I am currently working through the tutorial on Django's website. Upon completing the following
I'm currently working through the notepad tutorial, and exercise 2 completes the code to
I'm currently working my way through various Rails tutorials, but all seem to recommend
I am following the Ruby on Rails tutorial by Michael Hartl http://ruby.railstutorial.org/ I installed
I'm currently working through Professional Plone 4 Development while using the unified installer for
I'm attempting to do a release of some software and am currently working through

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.