ruby on rails - collection_select set option value of :include_blank to zero -


in rails app, have drop down box retrieve groups group table , display them using collection_select tag.

when user selects 'none', want pass '0' option value.

currently, empty string passed.

is there way include option value = 0 'none'?

<%= f.collection_select :sub_group, group.all, :group_id, :group_id, :include_blank => 'none' %> 

many many suggestion provided

if use options_for_select in combination select_tag can achieve using this:

options_for_select(    [['none', '0']].concat(       group.all.collect { |g| [g.group_id.to_s, g.group_id.to_s] }    ) ) 

in order keep views uncluttered, might want generalize , move helper method reasonable name.


Comments

Popular posts from this blog

Cursor error with postgresql, pgpool and php -

delphi - ESC/P programming! -

c++ - error: use of deleted function -