3

I am using highvoltage gem for static page serving. Its working but the url is ugly. Currently the url is like bellow:

localhost:3000/pages/terms-and-conditions?locale=en

But i want the url to be like bellow:

localhost:3000/en/pages/terms-and-conditions

In my routes file i wrote

scope ":locale", locale: /en|bn|hi/ do
  match "pages/:id" => 'pages#show', :as => :page, :format => false
end

then in view i wrote:

<%=link_to "Terms & Conditions", page_path(:id=>'terms-and-conditions')%>

in pages controller i wrote

  def show
    render params[:id]
  end

what can i do now to solve this problem

Nithin
  • 3,679
  • 3
  • 30
  • 55
monsur
  • 601
  • 6
  • 18

1 Answers1

1

I updated the issue on GitHub: https://github.com/thoughtbot/high_voltage/issues/144

Here are the the instructions I posted on GitHub issues:

Add a before filter to your Application controller

# app/controllers/application_controller.rb
before_action :set_locale

def set_locale
  I18n.locale = params[:locale] || I18n.default_locale
end

Disable the default High Voltage routes

# config/initializers/high_voltage.rb
HighVoltage.configure do |config|
  config.routes = false
end

Set up nested URLs with locales the routes file

# config/routes.rb
scope "/:locale", locale: /en|bn|hi/ do
  get "/pages/:id" => 'high_voltage/pages#show', :as => :page, :format => false
end

Add a page to the site

# app/views/pages/about.html.erb
<%= t 'hello' %>

Make sure that there are corresponding locale files

/config/locale/en.yml
/config/locale/bn.yml

One last note is there is a know issue with High Voltage.

You'll need to specify routes like this <%= link_to 'About Us', page_path(id: 'about') %>

Let me know if you're still having issues with this and I can add some more details.

harlow
  • 844
  • 9
  • 17