I''m trying to make a change to a field in the model whenever someone
accesses it and it''s incorrect. So I have the following in my
ActiveRecord class:
def status
prev_status = read_attribute(:status)
if end_date < Date.today
update_attribute(:status, "Expired")
end
status
end
I''m getting a "stack level too deep error". Any suggestions
on how to
fix and the correct approach to this.
thanks
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Hi Allen, I''m not sure, but this seems to be a before or after save filter, if it''s before_save, instead of update_attribute, just call write_attribute, when the model is saved it will automatically save this new value, if it''s an after filter, make it a before one. On Wed, Oct 8, 2008 at 11:09 PM, Allen Walker <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I''m trying to make a change to a field in the model whenever someone > accesses it and it''s incorrect. So I have the following in my > ActiveRecord class: > > def status > prev_status = read_attribute(:status) > if end_date < Date.today > update_attribute(:status, "Expired") > end > status > end > > I''m getting a "stack level too deep error". Any suggestions on how to > fix and the correct approach to this. > > thanks > -- > Posted via http://www.ruby-forum.com/. > > > >-- Maurício Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) João Pessoa, PB, +55 83 8867-7208 --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom wrote:>> end >> >> I''m getting a "stack level too deep error". Any suggestions on how to >> fix and the correct approach to this. > > You''re calling status from within status so it''s recursing forever. > > Replace that last status with read_attribute(:status) after perhaps > reloading the object to ensure you''ve got the latest.Yeah that is was. Simple calling ''read_attribute(:status)'' instead of ''status'' did the trick. thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---