Note that there are some explanatory texts on larger screens.

plurals
  1. POInternationalization of static pages with Rails
    primarykey
    data
    text
    <p>I feel like I'm missing something really simple and I keep spinning my wheels on this problem.</p> <p>I currently have internationalization working throughout my app. The translations work and the routes work perfectly. At least, most of the site works with the exception of the routes to my two static pages, my "About" and "FAQ" pages.</p> <p>Every other link throughout the app points to the proper localized route. For example if I select "french" as my language, links point to the appropriate "(/:locale)/controller(.:format)." However, despite the changes I make throughout the app my links for the "About" and "FAQ" refuse to point to "../fr/static/about" and always point to "/static/about."</p> <p>To make matters stranger, when I run rake routes I see: "GET (/:locale)/static/:permalink(.:format) pages#show {:locale=>/en|fr/}"</p> <p>and when I manually type in "../fr/static/about" the page translates perfectly.</p> <p>My Routes file:</p> <pre><code> devise_for :users scope "(:locale)", :locale =&gt; /en|fr/ do get 'static/:permalink', :controller =&gt; 'pages', :action =&gt; 'show' resources :places, only: [:index, :show, :destroy] resources :homes, only: [:index, :show] match '/:locale' =&gt; 'places#index' get '/'=&gt;'places#index',:as=&gt;"root" end </code></pre> <p>My ApplicationController:</p> <pre><code>before_filter :set_locale def set_locale I18n.locale=params[:locale]||I18n.default_locale end def default_url_options(options={}) logger.debug "default_url_options is passed options: #{options.inspect}\n" { :locale =&gt; I18n.locale } end </code></pre> <p>and My Pages Controller:</p> <pre><code>class PagesController &lt; ApplicationController before_filter :validate_page PAGES = ['about_us', 'faq'] def show render params[:permalink] end def validate_page redirect_to :status =&gt; 404 unless PAGES.include?(params[:permalink]) end end </code></pre> <p>I'd be very grateful for any help ... it's just been one of those days.</p> <p><em>Edit:</em> Thanks to Terry for jogging me to include views.</p> <pre><code>&lt;div class="container-fluid nav-collapse"&gt; &lt;ul class="nav"&gt; &lt;li class="dropdown"&gt; &lt;a href="#" class="dropdown-toggle" data-toggle="dropdown"&gt;&lt;%= t(:'navbar.about') %&gt;&lt;b class="caret"&gt;&lt;/b&gt;&lt;/a&gt; &lt;ul class="dropdown-menu"&gt; &lt;li&gt;&lt;%=link_to t(:'navbar.about_us'), "/static/about_us"%&gt;&lt;/li&gt; &lt;li&gt;&lt;%=link_to t(:'navbar.faq'), "/static/faq"%&gt;&lt;/li&gt; &lt;li&gt;&lt;%=link_to t(:'navbar.blog'), '#' %&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload