开发者

rails - select_tag default to blank when using map

开发者 https://www.devze.com 2023-01-08 17:22 出处:网络
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]}, \" \") %&g

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开发者_Python百科 it to blank. any ideas ?

Thanks, Alex


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 :)

0

精彩评论

暂无评论...
验证码 换一张
取 消