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 8892601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:02:39+00:00 2026-06-14T23:02:39+00:00

WHAT AM I TRYING TO ACHIEVE I have a html select box. The select

  • 0

WHAT AM I TRYING TO ACHIEVE

I have a html select box. The select box is responsible for selecting the preferred languages. for instance if a page is displayed in Germany then the select box should display Germany as its preference and likewise for the other languages.

WHAT HAVE BEEN DONE SO FAR

In application.html.erb I have below code

#application.html.erb

<select name="language" onChange="location = this.options[this.selectedIndex].value;">
    <% @langs.each_pair do |short, long| %>
    <option value="/<%= short %>/<%= @rem %>" <% if short==@langu %> selected="selected"<% end %>><%= long %></option>
    <% end %>
</select>

In application_controller.rb I have below code

#application_controller.rb
@string = request.fullpath
@langu  = @string.split("/")
@rem    = @string.split("/#{@langu[1]}/")
@langu  = @langu[1]
@rem    = @rem[1]

@langs = { :en => 'english', 
           :es => 'espaniol', 
           :de => 'germany', 
           :fr => 'french', 
           :it => 'italy' }

WHAT IS NOT WORKING

When user views a website in English/Spanish/Germany OR selects from the list, the select box evidently should show the particular language. i.e. if English then english, if Spanish then espaniol and so on. This is the exact thing not working

WHAT IS WORKING

If the user selects the preferred language (lets say Spanish) from the select box it renders the specific page, however the select box displays english which in essence should be espaniol.

Thanks!

  • 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-14T23:02:41+00:00Added an answer on June 14, 2026 at 11:02 pm

    There’s just a minor typo in your string. It should be selected='selected', so it should work like this:

    <select name="language" onChange="location = this.options[this.selectedIndex].value;">
    <% @langs.each_pair do |short, long| %>
    <option value="/<%= short %>/<%= @rem %>" <% if @short==@langu %> selected="selected"<% end %>><%= long %></option>
    <% end %>
    </select>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What I'm trying to achieve is a scrollable tab-bar. I have a web page
In my HTML page I have 2 select menus with IDs month and day
I have 3 drop down boxes, created using the HTML select tag. On page
I have a html like shown bellow. What im trying to achieve is, after
What I am trying to achieve is to have two control modes, a free
I have something I am trying to achieve. I have a web application running
I'm trying to achieve the following: I have a directory with multiple video files
im trying to achieve something but i dont really know how I have set
I am trying to achieve an LDAP query to gather all properties we have
I have been trying very hard to achieve rounded corners with IE6+jquery ui tabs.

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.