Tuesday, October 27, 2009

Ruby on Rails : Dynamic drop down list - onchange

In views page
  <% @people = Person.find(:all) %>  
<%= javascript_include_tag "prototype" %>

<%= collection_select :person, :id, @people, :id, :firstname,
{:include_blank => false},
{:onchange => remote_function(:url => {:action => 'say_hello'},
:with => "'id=' + this.value",
:update => "mydiv")} %>

<div id="mydiv">
<%= render :partial => "people/show"%>

In controller
  def say_hello
@person = Person.find(params[:id])
render :partial => "people/show"

Taken From : http://www.ruby-forum.com/topic/187488 [RoR & Ajax]
Other Resource : http://delta-knight.co.uk/jump-to.shtml [HTML & JS]


  1. drop down example in rubyon rails 4 with one to many relation table and insert to db.......cal any body help me to solve this situation

  2. This is an amazing blog,it gives very helpful messages to us.Besides that Wisen has established as Best Javascript Training in Chennai . or learn thru JavaScript Online Training India. Nowadays JavaScript has tons of job opportunities on various vertical industry