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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:46:25+00:00 2026-05-26T10:46:25+00:00

I’m upgrading a rails 2 app to rails 3 and in the user registration

  • 0

I’m upgrading a rails 2 app to rails 3 and in the user registration I’ve a county select, but this is not working in rails 3.1.

The scenario if I select US it should list all states in US similarly if its Canada it list all the states in Canada, with out refreshing the page

Here is the code

in my view…

 <%
        country_codes = []
        country_names = []
        @content_data['available_contact_countries'].each {|country_obj|
            country_codes << country_obj.getIsoCode()
            country_names << country_obj.getName()
        }
    %>
    <%=
        select_html(
            :name => 'country',
            :values => country_codes,
            :labels => country_names,
            :selected => @content_data['country'],
            :tabindex => get_next_tabindex(@content_data),
            :onchange => "getContactCountryStates(this.options[this.selectedIndex].value,'');"
        ).html_safe
    %>
        </td>
      </tr>
     <tr>
          <td class="key" nowrap="nowrap">
 <%=
      display_form_label(
          :label => @content_data['label_state'] + ':',
          :field_name => 'state',
          :error_fields => flash['error_fields'],
          :required => true
      ).html_safe
  %>
          </td>
        <td>
    <%
        state_codes = []
        state_names = []
    %>
 <div id="state_div">
    <%=
        select_html(
            :name => 'state',
            :id => 'state_id',
            :values => state_codes,
            :labels => state_names,
            :tabindex => get_next_tabindex(@content_data)
        ).html_safe
    %>

This is my javascript as I placed it in the view file itself

   <script language="javascript" type="text/javascript">
      function getContactCountryStates(country_code,state_code) {

    var tab_index = document.getElementById('state_id').tabIndex;

    var v_name = 'state';
    var v_id = 'state_id';
    if (country_code != '') {
      new Ajax.Updater(
          "state_div",
          '<%=
                url_for(
                    :controller => controller.controller_name,
                    :action => 'get_country_states'
                )
          %>',
          {
              asynchronous: true,
              evalScripts: true,
              method: "get",
              parameters: 'country_code=' + country_code+'&state_code='+state_code+'&tab_index='+tab_index+'&v_name='+v_name+'&v_id='+v_id,
              onFailure: function(request) {
                  alert(request.responseText);
              }
          }
      );
    }
}

<% if (@content_data['country'] != '') %>
    getContactCountryStates('<%= @content_data['country'] %>',
                     '<%= @content_data['state'] %>');
<% end %>

and my controller

 def get_country_states

    country_code = params['country_code'] or raise \
      'country_code parameter is missing'
    v_name = params['v_name']  or raise \
      'v_name parameter is missing'
    v_id = params['v_id']  or raise \
      'v_id parameter is missing'

    state_code = params['state_code']
    tab_index = params['tab_index'] || ''

    user_manager = Java::com.mysentry.entity.user.UserManager.new()
    actor = user_manager.getSystemUser()
    state_manager = \
      Java::com.mysentry.entity.contact.StateManager.new()

    @content_data['states'] = \
      state_manager.findStatesForCountry(country_code,actor)
    if (@content_data['states'].size() == 0)
        @content_data['states'].add(state_manager.findOtherState(actor))
    end
    @content_data['selected_state'] = state_code
    @content_data['tab_index'] = tab_index
    @content_data['v_name'] = v_name
    @content_data['v_id'] = v_id
    render(:template => 'get_country_states', :nolayout => true)
end

def send_data(data, options = {})
    super(data, options)
end

and I believe i loaded all the javasrcipt files

 <script src="/assets/defaults.js" type="text/javascript"></script>

  <script src="/assets/prototype.js?body=1" type="text/javascript"></script>
  <script src="/assets/prototype.js?body=1" type="text/javascript"></script>
  <script src="/assets/prototype_ujs.js?body=1" type="text/javascript"></script>
  <script src="/assets/effects.js?body=1" type="text/javascript"></script>
  <script src="/assets/dragdrop.js?body=1" type="text/javascript"></script>
  <script src="/assets/controls.js?body=1" type="text/javascript"></script>
  <script src="/assets/jquery.js?body=1" type="text/javascript"></script>
  <script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
  <script src="/assets/application.js?body=1" type="text/javascript"></script>
  <script src="/assets/rails.js" type="text/javascript"></script>
  <meta content="authenticity_token" name="csrf-param" />
  <meta content="KjqVznID2tqlycRcowaN/lNGQogHNjxM4NP1qs3q358=" name="csrf-token" />
  <script src="/assets/../javascripts/admin/menu.js" type="text/javascript"></script>
    <script src="/assets/../javascripts/tooltip.js" type="text/javascript"></script>
   <script language="javascript" type="text/javascript">
     function hidePopup() {
      Element.replace('overlay', '<div id="overlay"></div>')
      var body_elem = $('page');
      body_elem.removeClassName('body-overlayed');
      new Ajax.Request('/client/client/update_messages',
        {asynchronous:true, evalScripts:true});
  }

  • 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-05-26T10:46:25+00:00Added an answer on May 26, 2026 at 10:46 am

    I figure out how what was the problem,

    I’m using both prototype and jquery, so there is some conflict there to avoid the conflict we need to add

    <script type="text/javascript">jQuery.noConflict();</script> and also we need to change the form tag as well
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
This could be a duplicate question, but I have no idea what search terms
I need to clean up various Word 'smart' characters in user input, including but
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,

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.