routing issue on match '/:locale'

55 views
Skip to first unread message

Erwin

unread,
Nov 13, 2012, 9:31:16 AM11/13/12
to rubyonra...@googlegroups.com
I have set 

 match '/:locale' => "welcome#home",  :as => :root

but it doesn't cover the default case, when user enter the domain url wo locale, http://www.myapp.com

Is there any way to default it to the app default locale   I18n.locale ??

thanks for feedback 

Werner

unread,
Nov 13, 2012, 9:37:06 AM11/13/12
to rubyonra...@googlegroups.com
Hallo Erwin..

When you work with

before_filter :set_locale

  def set_locale
    # update sessions if passed
    session[:locale] = params[:locale] if params[:locale]

    # set locale based on sessions or default
    I18n.locale = session[:locale] || I18n.default_locale
  end

just create

index.html.erb
index.en.html.erb

ect..


Gruss

Werner

unread,
Nov 13, 2012, 9:38:55 AM11/13/12
to rubyonra...@googlegroups.com
root :to => 'welcome#index'

is enough

Erwin

unread,
Nov 14, 2012, 5:42:21 AM11/14/12
to rubyonra...@googlegroups.com
Thanks Werner, I'm quite there .. I am working as you mentionned ..
but I don't understand why I still have  the locale parameter in my root_url :

in the console :
root_url
root_path
"/?locale=en"
I18n.locale
:en

I would like to have :
root_path
"/en"

as root_url doesn't pass thru  url_for, I cannot play with it ...   where is it generated ?

erwin

Erwin

unread,
Nov 14, 2012, 6:10:06 AM11/14/12
to rubyonra...@googlegroups.com
[SOLVED]  writing my previous post, make me thinking about ...
  def default_url_options(options={})
    { :locale => I18n.locale }
  end

which was still in in my application controller .....  removed it , now it's fine..

thanks again !!

Werner Laude

unread,
Nov 14, 2012, 7:31:24 AM11/14/12
to rubyonra...@googlegroups.com

Am 14.11.2012 um 11:42 schrieb Erwin <yves_...@mac.com>:

Hi Erwin.. my be you check This.

gem 'i18n_routing'
Gruss


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/DLwJBQxQZyEJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Werner Laude



Erwin

unread,
Nov 15, 2012, 2:37:50 AM11/15/12
to rubyonra...@googlegroups.com, webagent...@googlemail.com
thanks , helpful
Reply all
Reply to author
Forward
0 new messages