Curtis Jennings Schofield
2010-Jan-05 06:40 UTC
Alias_method_chain on a boolean attribute not calling ...
I have the below code - I cannot use alias_method_chain unless I
declare :accepted= before using it - i suppost the attribute methods
are added latter - I suspect that this case is blowing away my
alias_method_chain
How can i complete this intention correctly, doing it the rails-way and pretty?
Thanks
Curtis.
class IncomingVideo < ActiveRecord::Base
validates_presence_of :content_url
validates_presence_of :title
def uncurated?
!accepted?
end
def accepted=(val)
update_attribute(:accepted,val)
end
def accepted_with_create_curated_video=(val)
if uncurated? and val == true
cv = CuratedVideo.create(:title => title,
:description => description,
:content_url => content_url,
:site_url => site_url)
cv.save!
end
accepted_without_create_curated_video=val
end
alias_method_chain :accepted=,:create_curated_video
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.
Matt Jones
2010-Jan-06 04:40 UTC
Re: Alias_method_chain on a boolean attribute not calling ...
On Jan 5, 1:40 am, Curtis Jennings Schofield <curtis.schofi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have the below code - I cannot use alias_method_chain unless I > declare :accepted= before using it - i suppost the attribute methods > are added latter - I suspect that this case is blowing away my > alias_method_chain > > How can i complete this intention correctly, doing it the rails-way and pretty? >You''ll likely want to do this in an after_save callback, as the method you''ve posted (if it worked) would end up drooling stray CuratedVideo records into the DB every time a model set that value (perhaps via mass-assignment) then didn''t pass validation. --Matt Jones -- 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.
Curtis Jennings Schofield
2010-Jan-06 05:26 UTC
Re: Re: Alias_method_chain on a boolean attribute not calling ...
On Tue, Jan 5, 2010 at 9:40 PM, Matt Jones <al2o3cr-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Jan 5, 1:40 am, Curtis Jennings Schofield > <curtis.schofi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> I have the below code - I cannot use alias_method_chain unless I >> declare :accepted= before using it - i suppost the attribute methods >> are added latter - I suspect that this case is blowing away my >> alias_method_chain >> >> How can i complete this intention correctly, doing it the rails-way and pretty? >> > > You''ll likely want to do this in an after_save callback, as the method > you''ve posted (if it worked) would end up drooling stray CuratedVideo > records into the DB every time a model set that value (perhaps via > mass-assignment) then didn''t pass validation. > > --Matt JonesThanks for your response - after i realized that it wasn''t going to work - i did use a call back and the _changed? and _was parts of the dirty attribute and it was as clean as i prefer and passed spec (and as you said - avoided extra useless queries). -- 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.