Skip to content

Instantly share code, notes, and snippets.

@thehenster
Created May 19, 2014 16:18
Show Gist options
  • Save thehenster/183c3efefa6343895452 to your computer and use it in GitHub Desktop.
Save thehenster/183c3efefa6343895452 to your computer and use it in GitHub Desktop.
Delegation of class methods through an association..
class Event < ActiveRecord::Base
has_many :artists
end
class Artist < ActiveRecord::Base
def self.make_me_an_artist
create! do |artist|
artist.cached_event_time = artist.event.time
end
end
end
event = Event.create(time: "3pm")
event.artists.make_me_an_artist
event.artists.first.cached_event_time #=> "3pm"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment