I might be totally confused and off target here.
I have an Event model, which has_one a Timeline that belongs_to Event. The Timeline has_many TimelineItems that belong_to Timeline.
def Event
has_one :timeline
end
def Timeline
belongs_to :event
has_many :timeline_items
end
def TimelineItem
belongs_to :timeline
end
create_table :admin_timeline_items do |t|
t.references :admin_timeline
t.references :user
t.references :resource, :polymorphic => true
t.string :method
end
So through from a TimelineItem object I would be able to generate for example this output:
eml created the Post “Hi this is from eml” on [DATE]
The title “Hi this is from eml” would come from the Post object’s .title. So eg. this TimelineItem has these settings
item.user = User.where(:username => "eml")
item.resource_type = "Post"
item.resource_id = 1
item.created_at = 27/082...13:37
So the problem is fetching said Post object, or rather the correct syntax for this particular association. Seems terribly simple to me, but I am not finding the information I need to properly write it.
Thanks for your help & time.
Sorry… I was just confusing myself because I had set resource_id in my own test item to a faulty value. My first guess was correct. It is quite simple:
Access resource like so: