views:

22

answers:

1

hey,

I want to have my select_tag default to blank but i'm using a map

<%= select_tag "assignment[client_id]", options_for_select(@data.map{|d| ["#{d.first_name} #{d.last_name}",d.id]}, " ") %>

I know you can't use include_blank and you can't put " " to set it to blank. any ideas ?

Thanks, Alex

+2  A: 

Rails provides the select helper method, which has a :include_blank option, use like:

<%= select("assignment", "client_id", @data.map { |d| ["#{d.first_name} #{d.last_name}", d.id] }, { :include_blank => true }) %>

See the Rails' FormOptionsHelper#select for more informations.

PS: OT: Maybe add a def name; "#{first_name} #{last_name}" end method to your model :)

lwe
Thanks for the reply! im using form_for so need to use select_tag any other ideas ?
Alex
afaik, then you can just do `f.select(:client_id, @data..., :include_blank => true)`, at least that's how I use it my code, doesn't that work?
lwe
got it working, changed how my form works :)
Alex