0

Suppose this form:

<% form_for(@student) do |f| %>
<%= f.select(:subject_id, 
             options_from_collection_for_select(@subjects, :id, :name), 
             {:prompt => 'Select a subject' },
             {:onChange => "#{remote_function(:update => :student_exam_id,
                                                         :url => { 
                                                            :action => :update_exams_list, 
                                                            :subject_id => 1
                                                         }
                                             )
                             }" } ) %>
<%= f.select(:exam_id, 
             options_from_collection_for_select(@exams, :id, :title) ) %>
<% end %>

When user selects a subject, then exams selector list must be updated with exams belongs to selected subject.

How can I send subject parameter to controller? I tried to send parameter using :subject_id => 1, but it does not work.

Please suggest me some ways to make this.

If you need more info, please ask me.

Thank you very much. Greetings.

Israel
  • 3,252
  • 4
  • 36
  • 54

2 Answers2

1

Hey, I could answer your question with details. Instead you should only watch this screencast:

http://railscasts.com/episodes/88-dynamic-select-menus

It explanins what you need and with more detailed instructions.

Hope it helps.

edgarjs
  • 506
  • 2
  • 9
0

I changed my select:

<%= f.select(:subject_id, 
             options_from_collection_for_select(@subjects, :id, :name), 
             {:prompt => 'Select a subject' },
             {:onChange => remote_function(:update => :student_exam_id,
                                           :url => { :action => :update_exams_list }, 
                                           :with => "'subject_id=' + this.value") } ) %>

and it works. :D

Israel
  • 3,252
  • 4
  • 36
  • 54