Hi, Having big problems with radio buttons that just don''t make sense: <%= radio_button "events", "impact_type", true %> Positive <%= radio_button "events", "impact_type", false %> Negative This should create two radio buttons with the first one checked by default, right? Cos it doesn''t :( Any ideas would be great, Thanks, Bex -- Posted via http://www.ruby-forum.com/.
Hi Becky, Try this instead: <%= radio_button "events", "impact_type", true, :checked => true %> The API for radio_button<http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M000395>indicates the 3rd param as the value of the radio button, not whether the checked attribute it set or not. But I guess you might have mistaken it with the API for radio_button_tag<http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#M000501> . -- choonkeat - http://blog.yanime.org/ - http://www.rssfwd.com/ On 8/10/06, Becky Franklin <Bex_3000@hotmail.com> wrote:> > Hi, > > Having big problems with radio buttons that just don''t make sense: > > <%= radio_button "events", "impact_type", true %> Positive > <%= radio_button "events", "impact_type", false %> Negative > > This should create two radio buttons with the first one checked by > default, right? Cos it doesn''t :( > > Any ideas would be great, > Thanks, > Bex > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060810/c8ef20f3/attachment.html
Becky Franklin wrote:> Hi, > > Having big problems with radio buttons that just don''t make sense: > > <%= radio_button "events", "impact_type", true %> Positive > <%= radio_button "events", "impact_type", false %> Negative > > This should create two radio buttons with the first one checked by > default, right? Cos it doesn''t :( > > Any ideas would be great, > Thanks, > Bextry 1 and 0 instead of true and false calling the boolean field directly gives you a 1 or 0. You only get the true/false if you call the method with a ? So the form helper tries to match the values of the option buttons to @events.impact_type, which gives a 1 or 0. -- Posted via http://www.ruby-forum.com/.
Becky Franklin wrote:> Hi, > > Having big problems with radio buttons that just don''t make sense: > > <%= radio_button "events", "impact_type", true %> Positive > <%= radio_button "events", "impact_type", false %> Negative > > This should create two radio buttons with the first one checked by > default, right? Cos it doesn''t :( > > Any ideas would be great, > Thanks, > BexHi, Try using <%= radio_button "events", "impact_type", "true", {:checked => ''checked''} %> hope this helps -cd -- Posted via http://www.ruby-forum.com/.