开发者

rails - select_tag default to blank when using map

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜