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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:00:51+00:00 2026-06-09T12:00:51+00:00

I can’t figure what i do wrong. I have few select lists: Regions Towns

  • 0

I can’t figure what i do wrong. I have few select lists:

  • Regions
  • Towns
  • Organizations

How it should works:

  1. User selects region.
  2. List of towns loads.
  3. User selects town.
  4. List of organizations loads.
  5. User chooses organization.

I use ajax for that and i realized only auto-loading for list of towns and i can’t do same thing for organization. Second select list DOESN’T POST at all!

Here is my code:

View

%div
  %br/
  = select 'ajax', :region_id, [['Choose your region...', -1]] + Region.all.map{|region| [region.name, region.id]}.sort
  = image_tag('ajax-loader.gif', :id => 'ajax-progress', :style => 'display: none;')
  = observe_field :ajax_region_id, :url => { :controller => :organizations, :action => :list_towns, :preselect => (defined?(preselect) && !preselect.nil?) }, :with => 'region_id', :update => 'select_organization_idd', :loading => '$("ajax-progress").show();', :complete => 'if (Ajax.activeRequestCount == 1) $("ajax-progress").hide();'
  %br/
  = select 'ajax2', :o_id, [], {}, {:id => 'select_organization_idd', :style => 'width: 60em;'}
  = image_tag('ajax-loader.gif', :id => 'ajax-progress', :style => 'display: none;')
  = observe_field :ajax_region2_id, :url => { :controller => :organizations, :action => :list_region, :preselect => (defined?(preselect) && !preselect.nil?) }, :with => 'o_id', :update => 'select_organization_idd2', :loading => '$("ajax-progress").show();', :complete => 'if (Ajax.activeRequestCount == 1) $("ajax-progress").hide();'

  = f.select :organization_id, [], {}, {:id => 'select_organization_idd2', :style => 'width: 60em;'}

Controller

  def list_region
    render :text => ActionController::Base.helpers.options_for_select((params[:preselect] ? [['Choose organization', -1]] : []) + Organization.map{|org| [ActionController::Base.helpers.truncate(org.name, :length => 155), org.id]})
  end

  def list_towns
    region = Region.find(params[:region_id])
    towns = Kladr.find(:all, :conditions => ['code LIKE ?', "#{region.code}%"])
    render :text => ActionController::Base.helpers.options_for_select([['Choose town', -1]] + towns.map{ |t| ["#{t.socr}. #{t.name}", t.id] })
  end

What do i do wrong? Also i use Rails 2, that why observe_field is not deprecated.

  • 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-09T12:00:52+00:00Added an answer on June 9, 2026 at 12:00 pm

    Do you use rails 3? The method observe_field is deprecated.

    With rails 3 you must do something like this :

    view

    %div
      %br/
      = select 'ajax', :region_id, [['Choose your region...', -1]] + Region.all.map{|region| [region.name, region.id]}.sort, {}, {:id => 'ajax1'}
      = image_tag('ajax-loader.gif', :id => 'ajax-progress', :style => 'display: none;')
      %br/
      = select 'ajax2', :o_id, [], {}, {:id => 'select_organization_idd', :style => 'width: 60em;'}, {}, {:id => 'ajax2'}
      = image_tag('ajax-loader.gif', :id => 'ajax-progress', :style => 'display: none;')
    
      = f.select :organization_id, [], {}, {:id => 'select_organization_idd2', :style => 'width: 60em;'}
    

    javascript.js.coffee

    $('#ajax1').change = () ->
      $.post(
        url: '/organizations/list_towns'
        data: {value: $('#ajax1').val()}
        success: () ->
          if (Ajax.activeRequestCount == 1) 
            $("ajax-progress").hide()
      )
    
    $('#ajax2').change = () ->
      $.post(
        url: '/organizations/list_regions'
        data: {value: $('#ajax2').val()}
        success: () ->
          if (Ajax.activeRequestCount == 1) 
            $("ajax-progress").hide()
      )
    

    The implementation is probably wrong and could be refactored. I didn’t test it. But you’ve got the idea.

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

Sidebar

Related Questions

Can't figure out how to do this in a pretty way : I have
Can't seem to figure out what's wrong with the simple getJSON call below. It's
Can I order my users in the database, so I don't have to say
I have a jquery bug and I've been looking for hours now, I can't
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Can anybody help me? What should be the datatype for this type -07:00:00 of
Can you have submenus with the top level set to checkable in WPF? I
can you recommend some good ASP.NET tutorials or a good book? Should I jump
Can this query below be optimized? select max(date), sysdate - max(date) from table; Query
Can a DateTime value be NULL ? I have this code: From here I

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.