valk
valk

Reputation: 9874

How javascript knows about the current locale in Rails 3?

I'm trying to get a resouce from my autocomplete.js.coffee(.erb) file. The resource's URL is dependent on the current locale. That is,

/en/ajax/posts

or

/he/ajax/posts

Please note the /en/.

The problem is, I cannot determine the locale from within the .js file.

Please help.

Upvotes: 2

Views: 1070

Answers (1)

valk
valk

Reputation: 9874

Solved with:

def set_locale
    I18n.locale = params[:locale] || session[:locale] || I18n.default_locale
    session[:locale] = I18n.locale  # store locale to session
end

It should be noted that the "standard" implementation is:

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

If you have a better answer, please suggest.

Upvotes: 3

Related Questions