byron appelt
2010-Dec-30 23:17 UTC
problem with accepts_nested_attributes_for and reject_if
I am trying to get reject_if to work using a method name instead of a
Proc. However I cannot seem to get this to work. A simplified version
of my model code is shown below. The problem is that I keep getting an
"undefined method `call'' for :not_wired?:Symbol" error. I am
using
Rails 2.3.4. Can anyone give me an idea of what might be going on
here?
class DeviceConfiguration < ActiveRecord::Base
has_one :obd_configuration
accepts_nested_attributes_for :obd_configuration, :reject_if
=> :not_obd?
has_one :wired_configuration
accepts_nested_attributes_for :wired_configuration, :reject_if
=> :not_wired?
def not_obd?(attrs)
!device_type.name.eql?("obd")
end
def not_wired?(attrs)
!device_type.name.eql?("wired")
end
end
--
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.
Philip Hallstrom
2010-Dec-31 00:12 UTC
Re: problem with accepts_nested_attributes_for and reject_if
On Dec 30, 2010, at 3:17 PM, byron appelt wrote:> I am trying to get reject_if to work using a method name instead of a > Proc. However I cannot seem to get this to work. A simplified version > of my model code is shown below. The problem is that I keep getting an > "undefined method `call'' for :not_wired?:Symbol" error. I am using > Rails 2.3.4. Can anyone give me an idea of what might be going on > here?2.3.4 doesn''t allow a symbol. Proc only. So either upgrade or switch over to using a Proc... -philip> > class DeviceConfiguration < ActiveRecord::Base > > has_one :obd_configuration > accepts_nested_attributes_for :obd_configuration, :reject_if > => :not_obd? > > has_one :wired_configuration > accepts_nested_attributes_for :wired_configuration, :reject_if > => :not_wired? > > def not_obd?(attrs) > !device_type.name.eql?("obd") > end > > def not_wired?(attrs) > !device_type.name.eql?("wired") > end > > end-- 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.
byron appelt
2010-Dec-31 16:17 UTC
Re: problem with accepts_nested_attributes_for and reject_if
Doh! Thanks, that was the problem, obviously. On Dec 30, 6:12 pm, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote:> On Dec 30, 2010, at 3:17 PM, byron appelt wrote: > > > I am trying to get reject_if to work using a method name instead of a > > Proc. However I cannot seem to get this to work. A simplified version > > of my model code is shown below. The problem is that I keep getting an > > "undefined method `call'' for :not_wired?:Symbol" error. I am using > > Rails 2.3.4. Can anyone give me an idea of what might be going on > > here? > > 2.3.4 doesn''t allow a symbol. Proc only. So either upgrade or switch over to using a Proc... > > -philip > > > > > > > > > > > class DeviceConfiguration < ActiveRecord::Base > > > has_one :obd_configuration > > accepts_nested_attributes_for :obd_configuration, :reject_if > > => :not_obd? > > > has_one :wired_configuration > > accepts_nested_attributes_for :wired_configuration, :reject_if > > => :not_wired? > > > def not_obd?(attrs) > > !device_type.name.eql?("obd") > > end > > > def not_wired?(attrs) > > !device_type.name.eql?("wired") > > end > > > end-- 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.
kirti parihar
2011-Jan-24 07:02 UTC
problem with accepts_nested_attributes_for and reject_if
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
--
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.
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|
a.all_blank? }, :allow_destroy => true
Can anyone give me an idea of what might be going wrong here?
Thanks
kirti
--
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.
Garrett Lancaster
2011-Jan-24 09:58 UTC
Re: problem with accepts_nested_attributes_for and reject_if
<HTML><HEAD><META content="text/html; charset=UTF-8" http-equiv="Content-Type"></HEAD><BODY>Try accepts_nested_attributes_for :educations, :reject_if => :all_blank, :allow_destroy => true<BR> <BR> Garrett Lancaster</BODY></HTML> <p></p> -- <br /> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.<br /> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org<br /> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org<br /> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.<br />
kirti parihar
2011-Jan-24 10:12 UTC
Re: problem with accepts_nested_attributes_for and reject_if
still its also not working... On Mon, Jan 24, 2011 at 3:28 PM, Garrett Lancaster < glancast-jmyiO2ngOJdad6c/EObmYVaTQe2KTcn/@public.gmane.org> 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 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.
Garrett Lancaster
2011-Jan-24 10:25 UTC
Re: problem with accepts_nested_attributes_for and reject_if
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 <mailto:pariharkirti24-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > 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 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. > ------------------------------------------------------------------------ > > Garrett Lancaster <mailto:glancast-jmyiO2ngOJdad6c/EObmYVaTQe2KTcn/@public.gmane.org> > January 24, 2011 3:58 AM > > > Try accepts_nested_attributes_for :educations, :reject_if => > :all_blank, :allow_destroy => true > > Garrett Lancaster > ------------------------------------------------------------------------ > > kirti parihar <mailto:pariharkirti24-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > January 24, 2011 1:02 AM > > > 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 > > -- > 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.-- 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.