Rails 3: select helper method default?
I currently have this select helper call:
<%= f.select :开发者_如何学Pythonmacro_process_id, MacroProcess.all.collect { |mp| [mp.name, mp.id]} %>
How can i change this that if :macro_process_id
has a value, then the selected element should be equal to that value?
If that makes any sense?
Thanks
Try
<%= f.select :macro_process_id, MacroProcess.all.collect { |mp| [mp.name, mp.id]}, MacroProcess.find(:macro_process_id) %>
The addition that I have made, will make it the default value selected among the other values.
For more info, look here: form-select-helper-in-ruby-on-rails
精彩评论