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:
- 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?
- 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. 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?