0

I have a dropdown in my rails partial which onchange calling a remote function...I am using rails2.3 verison.. In the drop down I am retreiving list of students like this..

<%= select :students, :id,
                     @students.map {|s| [s.name, s.id] },
                     {:prompt => "Select A Student"},
                     {:onchange => "#{remote_function(
                             :url => { :action => 'type' },
                             :method => 'get',
                             :with => "'stud_id='+value",
                             :before => "Element.show('loader')",
                             :success => "Element.hide('loader')"  )}"} %>

This is working fine... I get list of students with their ids as values.. But I need to add one more option as "All students" to the dropdown so that I can view the details of all the students. How would I achieve it. Please put your thoughts on this as I am new to rails and learning it...

4

1 回答 1

0

你可以做这样的事情。而不是使用

@students.map {|s| [s.name, s.id] }

您可以简单地向数组中添加一个空白项

[["All students",'']] + @students.map {|s| [s.name, s.id] }

我忘记了 Rails 2 是否允许您执行 { include_blank: true },它在以后的版本中可用。

于 2013-09-10T04:59:57.373 回答