Saturday, 15 June 2013

ruby on rails - Locale Switcher -



ruby on rails - Locale Switcher -

i busy going through pbp - agile web development rails , implementing locale switcher.

however when seek switch between english language , spanish error:

no route matches [post] "/en"

my controller follows:

class storecontroller < applicationcontroller skip_before_filter :authorize def index if params[:set_locale] redirect_to store_path(locale: params[:set_locale]) else @products = product.order(:title) @cart = current_cart end end end

and extract of application.hmtl.erb beingness used;

<div id="banner"> <%= form_tag store_path, class: 'locale' %> <%= select_tag 'set_locale', options_for_select(languages, i18n.locale.to_s), onchange: 'this.form.submit()' %> <%= submit_tag 'submit' %> <%= javascript_tag "$('.locale input').hide()" %> <% end %> <%= image_tag("logo.png") %> <%= @page_title || t('.title') %> </div>

the routing folder follows:

scope'(:locale)' resources :users resources :orders resources :line_items resources :carts resources :products :who_bought, on: :member end root to: 'store#index', as: 'store' end

cant figure out did wrong. if come in /en or /es in url works correctly. choosing in drop downwards created error mentioned

you missing slash in scope guides states:

# config/routes.rb scope "/:locale" resources :books end

http://guides.rubyonrails.org/i18n.html#setting-the-locale-from-the-url-params

ruby-on-rails ruby ruby-on-rails-4 rails-i18n

No comments:

Post a Comment