problem with accepts_nested_attributes_for and reject_if

1,014 views
Skip to first unread message

kirti parihar

unread,
Jan 24, 2011, 2:02:03 AM1/24/11
to rubyonra...@googlegroups.com
Hi, m using rails 3.0.3 and i m getting problem with reject_if .I just want to check the condition that if all fields of educations table are blank then reject otherwise their values should be stored in database.
but actually this saves blank also in database.

class Profile < ActiveRecord::Base

 has_many :educations, :dependent => :destroy
 accepts_nested_attributes_for :educations, :reject_if => proc { |a| a.blank? }, :allow_destroy => true

end
 

i have tried this also :
 accepts_nested_attributes_for :educationss, :reject_if => lambda { |a| a.blank? }, :allow_destroy => true

and also :
accepts_nested_attributes_for :educationss, :reject_if => lambda { |a| a.all_blank? }, :allow_destroy => true

Can anyone give me an idea of what might be going wrong here?

Thanks
kirti

Kirti

unread,
Jan 24, 2011, 2:08:49 AM1/24/11
to Ruby on Rails: Talk
Hi, m using rails 3.0.3 and i m getting problem with reject_if .I just
want to check the condition that if all fields of educations table are
blank then reject otherwise their values should be stored in database.
but actually this saves blank also in database.

class Profile < ActiveRecord::Base

has_many :educations, :dependent => :destroy
accepts_nested_attributes_for :educations, :reject_if => proc { |a|
a.blank? }, :allow_destroy => true

end


i have tried this also :
accepts_nested_attributes_for :educations, :reject_if => lambda { |a|
a.blank? }, :allow_destroy => true

and also :
accepts_nested_attributes_for :educations, :reject_if => lambda { |a|

Garrett Lancaster

unread,
Jan 24, 2011, 4:58:56 AM1/24/11
to rubyonra...@googlegroups.com
Try accepts_nested_attributes_for :educations, :reject_if => :all_blank, :allow_destroy => true

Garrett Lancaster

kirti parihar

unread,
Jan 24, 2011, 5:12:27 AM1/24/11
to rubyonra...@googlegroups.com
still its also not working...

On Mon, Jan 24, 2011 at 3:28 PM, Garrett Lancaster <glan...@garrettlancaster.com> wrote:
Try accepts_nested_attributes_for :educations, :reject_if => :all_blank, :allow_destroy => true

Garrett Lancaster

--
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 rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Garrett Lancaster

unread,
Jan 24, 2011, 5:25:45 AM1/24/11
to rubyonra...@googlegroups.com
Hmm...works fine for me, sounds like you have a problem somewhere else.

Here's the doc reference: http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html#method-i-accepts_nested_attributes_for

I would start with the obvious, are you getting the correct values in the params hash?

Garrett Lancaster



kirti parihar
January 24, 2011 4:12 AM

still its also not working...


--
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 rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.


Garrett Lancaster
January 24, 2011 3:58 AM

Try accepts_nested_attributes_for :educations, :reject_if => :all_blank, :allow_destroy => true

Garrett Lancaster


kirti parihar
January 24, 2011 1:02 AM
Reply all
Reply to author
Forward
0 new messages