Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8615013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:16:00+00:00 2026-06-12T05:16:00+00:00

I have categoried, which user choose. If user choose ‘Auto’ I need to replace

  • 0

I have categoried, which user choose. If user choose ‘Auto’ I need to replace it with result, what gives me my JavaScript function – setting default browser language.

Here is JavaScript example, of JS function – http://fiddle.jshell.net/xCgsb/

And here is my before_save filter in Website model:

before_save :auto_language

def create
 website = current_user.websites.new params[:website]
 if @website.language == "Auto"
  @website.language = request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first
 end
...
#error
undefined local variable or method `request' for #<Website:0x244e1b0>

Can someone help me with this trouble ? Any help appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:16:01+00:00Added an answer on June 12, 2026 at 5:16 am

    You should not be using Javascript to set up your default locale.

    Take a look at this:

    http://guides.rubyonrails.org/i18n.html#setting-the-locale-from-the-client-supplied-information

    They use Ruby to detect the locale

    def set_locale
       logger.debug "* Accept-Language: #{request.env['HTTP_ACCEPT_LANGUAGE']}"
       I18n.locale = extract_locale_from_accept_language_header
       logger.debug "* Locale set to '#{I18n.locale}'"
    end  
    
    private
    
    def extract_locale_from_accept_language_header
        request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first
    end
    

    If you want to get the full language, you can use a switch case:

    def full_language_name(lang) 
      case lang
        when 'ru'
          return 'Russian'
        when 'en'
          return 'English'
        when 'fr'
          return 'French'
        else
          return 'English'
    end
    

    The ‘else’ case is the default behavior if none of these conditions has been verified.
    The keyword ‘return’ is optional.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database which takes user submitted data, the entries from which I
I have a form which I need to validate the easiest and most safe
I have a Categories table in which each category has a ParentId that can
I have a categories table, which one of the fields serves as the foreign
I have a class which models all categories and they can be ordered hierarchically.
I have a simple SQL table which defines a set of hierarchical categories and
I have the following script currently, which gets the category IDs as arrays: $sql_select_categories
I have a Wordpress website in which one of the categories I've stripped the
I have a bug which makes my website freeze in PHP. It occurs on
I'm writing an app in which there will be user defined categories which will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.