Hey Guys,
I''m stumped with something, hoping somebody can help.
Basically, I''m trying to override the default belongs_to accessor.
For example, I have an Event model, that belongs_to a Venue:
class Event < ActiveRecord::Base
belongs_to :venue
...
end
The venue is not always set, so sometimes "event.venue" returns null.
I want to be able to override "event.venue", and provide my own code
that grabs the venue if it doesn''t exist. I was thinking I could do
something like:
def venue
if self.send(:venue) == nil
# code to fetch the venue and insert into db
else
self.send(:venue)
end
end
Clearly though, this doesn''t work, because self.send(:venue) just calls
itself, and ruby barfs on a stack overflow from the recursion.
The workaround is to create a "get_venue" method, and always call that
instead of "venue," but that seems kind of icky.
Any ideas?
Spencer
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---