How do I reject the creation of an object if all of the attributes are
blank?
accepts_nested_attributes_for :questions, :allow_destroy =>
true, :reject_if => lambda {|a| a.each.blank? }
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Abhinav Saxena
2010-Apr-14 15:38 UTC
Re: Rejecting a nested object if all attributes are blank
You can do like this using all? method
accepts_nested_attributes_for :questions, :allow_destroy => true,
:reject_if => lambda { |attrs| attrs.all? { |k, v| v.blank?}}
--
Thanks,
Abhinav
http://twitter.com/abhinav
On Wed, Apr 14, 2010 at 7:51 PM, ES
<emstolfo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> How do I reject the creation of an object if all of the attributes are
> blank?
>
> accepts_nested_attributes_for :questions, :allow_destroy =>
> true, :reject_if => lambda {|a| a.each.blank? }
>
> --
> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
>
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
that works, thanks! On Apr 14, 5:38 pm, Abhinav Saxena <abhinav...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You can do like this using all? method > > accepts_nested_attributes_for :questions, :allow_destroy => true, > :reject_if => lambda { |attrs| attrs.all? { |k, v| v.blank?}} > > -- > Thanks, > Abhinavhttp://twitter.com/abhinav > > On Wed, Apr 14, 2010 at 7:51 PM, ES <emsto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > How do I reject the creation of an object if all of the attributes are > > blank? > > > accepts_nested_attributes_for :questions, :allow_destroy => > > true, :reject_if => lambda {|a| a.each.blank? } > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Does that still reject the object if the id attribute is not blank? Do I have to test each attribute separately and exclude the id attribute in order for that to work? On Apr 14, 5:38 pm, Abhinav Saxena <abhinav...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You can do like this using all? method > > accepts_nested_attributes_for :questions, :allow_destroy => true, > :reject_if => lambda { |attrs| attrs.all? { |k, v| v.blank?}} > > -- > Thanks, > Abhinavhttp://twitter.com/abhinav > > On Wed, Apr 14, 2010 at 7:51 PM, ES <emsto...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > How do I reject the creation of an object if all of the attributes are > > blank? > > > accepts_nested_attributes_for :questions, :allow_destroy => > > true, :reject_if => lambda {|a| a.each.blank? } > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.