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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:18:31+00:00 2026-05-31T23:18:31+00:00

I am a newbie to Ruby on Rails . I have started working on

  • 0

I am a newbie to Ruby on Rails . I have started working on RoR 1 month back.
My problem is:

I have a single table called syscode which has Id ,Name ,Desc and Parent_id .
For parent the Parent_id=0 and for childs they have parent_id according to the id of the parent.

I should have two select boxes in which the first select box should display the parents and the second select box should be dynamic i.e On click of parent in the first select box it should display the respective childs in the second select box.
I am successful in getting the parent_id on click of the options in the first select box.

The code i have tried is:

View : selectnew.html.erb

<div id="dvSelectSyscodeForm">  
  <%= form_for(@syscode) do |f| %>
    <div class="field">
      <label for="syscode_fksyscodeparent">Parent</label>
      <%= f.select :fksyscodeparent, Syscode.where("fksyscodeparent = '0'").map {|s| ["#{s.syscode}", s.id ]} %>
    </div>
    <div id="dvShowChild" style="display:none;">
      <div class="field">
        <label for="childSyscodes">Child</label>
        <%= f.select :fksyscodeparent, Syscode.where("fksyscodeparent = '0'").map {|s| ["#{s.syscode}", s.id ]} %>
      </div> 
    </div>
    <script type="text/javascript">
      var scode = [];
      function parentSelected() {        
        parent_id = $('#syscode_fksyscodeparent').val();
        alert(parent_id);          
      }    

      $(document).ready(function() {
        parentSelected();
        $('#syscode_fksyscodeparent').change(parentSelected);
      });

    </script>
    <% end %>  
    </div>
    <%= link_to 'Back', syscodes_path %>

Controller : selectnew

def selectnew
  @syscode = Syscode.new
  respond_to do |format|
    format.html # selectnew.html.erb
    format.json { render json: @syscode }
  end
end

Please help me guys … Thank You in Advance …!!

  • 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-31T23:18:32+00:00Added an answer on May 31, 2026 at 11:18 pm

    You need to do an Ajax call in your parentSelected function. The return from this Ajax call should be javascript that replaces the content of “dvShowChild” with new html content for the currently selected parent.

    Alternatively you could do an ajax call that fetches html and then in the success callback replace the html value of “dvShowChild” with the html returned from the ajax call.

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

Sidebar

Related Questions

I am a ruby and rails newbie. And I am working on a rails
Complete rails newbie trying to get started. I have two classes, Ingredient, and Unit.
I'm a newbie o thin. I have a ruby on rails application. Today I
I have mysql table called it as R which contains many fields, but I
I am just starting to learn Ruby on Rails and have a newbie question
am a newbie in ruby on rails and am stuck with a simple problem
I have the following code. I'm still a newbie in Ruby on Rails. As
I'm a newbie following the RailsTutorial.org program and have installed/setup rvm, ruby 1.9.2,rails, curl,
I a newbie trying to write a [Ruby ON Rails] spec to make sure
I am newbie in Ruby.. seeking some help.. I have a code DB =

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.