This is the code which I am using for select_tag.
<td align='center'>
<% driver = d.driver ? d.driver : nil %>
<% selected = d.driver.nil? ? 0 : d.driver.id %>
<% current_drivers = @current_user.sorted_drivers.collect{ |u| [u.name,
u.id]} %>
<%= select_tag(:id, options_for_select( [["Select", 0]] +
current_drivers, selected ),
:onchange => ( "if (confirm('Would you like to assign driver ' +
this.options[this.selectedIndex].text + ' to device #{ d.s_uf_name}?'))
{" + remote_function(
:url=> { :controller => :limos, :action => :updatedrivervehicle,
:device_id => d.id, :predriver_id => d.driver}, :method => :post,
:with => with_params( :driver_id
=>'this.options[this.selectedIndex].value' )) + "; sdvs[#{ i }] =
this.selectedIndex; } else { this.selectedIndex = sdvs[#{ i }]; }")) %>
<% old_index= driver ? (current_drivers.index( [driver.name,driver.id]
))+1 : 0 %>
<%= javascript_tag "sdvs[#{ i }] = #{old_index} " %>
</td>
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment