I''m puzzled by this latest commit: "Tag helper should output an attribute with the value ''false'' instead of omitting the attribute, if the associated option is false but not nil." http://github.com/rails/rails/commit/4e9abdd7f1b4e05f8d1b50ddaa080b3ff63b92d9 What was the reason for this? How does it help in HTML? Thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
2008/11/14 <koziarski@gmail.com>> f.hidden_field :some_boolean_attribute > > when the value is false, it gets turned into value = "", which gets turned > into nil by attributes=. Does it break something of yours?So it''s about boolean fields and form serialization. Got it. No, nothing broke for me, I was just wondering why output the attribute at all. In HTML, foo="false" means that foo is true. Much more correct for attribute specified in Ruby as { :foo => false } is to produce no output at all, and that we put some special-casing to form helpers like `hidden_field` to convert booleans to strings prior to sending these attributes to common tag helpers. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
On Nov 13, 11:55 pm, "Mislav Marohnić" <mislav.maroh...@gmail.com> wrote:> I''m puzzled by this latest commit: > "Tag helper should output an attribute with the value ''false'' instead of > omitting the attribute, if the associated option is false but not nil."http://github.com/rails/rails/commit/4e9abdd7f1b4e05f8d1b50ddaa080b3f... > > What was the reason for this? How does it help in HTML? ThanksIt''s because Rails 2.2 changed the way empty strings are mapped to boolean model attributes. Migration: create_table :people do |t| t.boolean :is_alien, :null => false end Rails 2.1: p = Person.new(:is_alien => "") p.is_alien # => false p.save # => true Rails 2.2: p = Person.new(:is_alien => "") p.is_alien # => nil p.save # => StatementInvalid: value for is_alien may not be null in INSERT statement! In my controller I have this: def new @person = Person.new @person.is_alien = false end def create @person = Person.new(params[:person]) @person.save end In the ''new'' view: <% form_for @person do |f| %> <%= f.hidden_field :is_alien %> Before this commit, the hidden_field helper would output: <input type="hidden" name="person[is_alien]" /> As you can see, there''s no "value" attribute. Upon submitting the form, @person.is_alien would be set to nil instead of the expected false, causing an SQL error. This is solved by making hidden_field output value="false": <input type="hidden" name="person[is_alien]" value="false" /> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
2008/11/14 Hongli Lai <hongli@phusion.nl>> > Before this commit, the hidden_field helper would output: > <input type="hidden" name="person[is_alien]" /> > As you can see, there''s no "value" attribute. Upon submitting the > form, @person.is_alien would be set to nil instead of the expected > false, causing an SQL error. This is solved by making hidden_field > output value="false": > <input type="hidden" name="person[is_alien]" value="false" />Thanks Koz for a brief and Hongli for more detailed explanation, but I don''t think you got my question right. You guys are talking about (hidden) textual form controls that map to booleans. That''s fine. I''m talking about HTML attribute serialization in general, meaning *everything besides* textual form controls mapping to booleans, and why I think this commit should be reverted. This is the reason: <% tag :input, :type => "checkbox", :checked => false %> Who here thought that this creates a text input that isn''t checked? Well, you thought wrong. This generates an initially checked box. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Michael Koziarski
2008-Nov-18 19:33 UTC
Re: About HTML attributes with the value ''false''
> <% tag :input, :type => "checkbox", :checked => false %> > Who here thought that this creates a text input that isn''t checked? Well, > you thought wrong. This generates an initially checked box.OK, I now follow you. A patch to fix this would be appreciated :) -- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
On Nov 18, 8:27 pm, "Mislav Marohnić" <mislav.maroh...@gmail.com> wrote:> Thanks Koz for a brief and Hongli for more detailed explanation, but I don''t > think you got my question right. > > You guys are talking about (hidden) textual form controls that map to > booleans. That''s fine. I''m talking about HTML attribute serialization in > general, meaning *everything besides* textual form controls mapping to > booleans, and why I think this commit should be reverted. This is the > reason: > > <% tag :input, :type => "checkbox", :checked => false %> > > Who here thought that this creates a text input that isn''t checked? Well, > you thought wrong. This generates an initially checked box.Good point. This has been fixed in http://github.com/rails/rails/commit/0f89ed5636f69c7ae75f99ca2a613b1918de5f95 I''ve registered ''checked'' as a boolean HTML attribute so that it doesn''t get outputted when its value is false. If you encounter more problems, then please suggest more attributes to register as boolean HTML attributes. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---