I have an employees table that contains fields that are boolean to control information formatting. The ''new'' method sets the value of the select box to the default value contained in the table. During the ''edit'' method these values are the table defaults not the values contained in the table. How can I change the following excerpt of _form.rhtml to use the table values contained in the record? Note: This is the code generated by the scaffold controller. <p><label for="employee_pubadd">Publish Address</label> <select id="employee_pubadd" name="employee[pubadd]"> <option value="false">False</option><option value="true">True</option></select></p> Thanks in Advance reback -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
As it stands, that is just static html. It''s not picking a default from anywhere. You need to use the select method as embedded ruby and add the :selected option. It will look something like this: <%= select ''employee'', ''pubadd'', [["true", "true"] , ["false", "false"]], :selected => @employee.pubadd ? @employee.pubadd : "false" %> I havent actually tried that but a bit of fiddling should get it doing what you want. steve -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> <%= select ''employee'', ''pubadd'', [["true", "true"] , ["false", > "false"]], :selected => @employee.pubadd ? @employee.pubadd : "false" %>Actually it looks like you don''t need the :selected option, rails does it anyway if @employee is set. steve -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks Steve, That works great! I knew that the html generated from the scaffolding was static. However I am surprised that the rails generators are not better at handling boolean type data fields. Richard -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---