Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7514149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:24:33+00:00 2026-05-30T00:24:33+00:00

I might be totally confused and off target here. I have an Event model,

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T00:24:35+00:00Added an answer on May 30, 2026 at 12:24 am

    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:

    class TimelineItem < ActiveRecord::Base
      belongs_to :timeline
      belongs_to :user
      belongs_to :resource, :polymorphic => true
    end
    

    Access resource like so:

    TimelineItem.first.resource
    => Post(....)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to mocking so I might have it totally wrong here but
Okay I might be entirely off track now but here goes: Our webshop offers
Ok so I might be totally barking up the wrong tree here as I'm
Initial Warning : Long post and I might have got the pattern totally wrong
Ok this might get confusing cos I have not totally worked out how to
Be aware that I might be doing this totally wrong, so I apologize in
OK, I'm guessing that this might be a bug but I'm not totally sure.
I'm totally stuck in a operation that might be really simple...adding Sparkle to a
Might be a bit of noob question but it's something that's been getting me
might be a stupid question but I seem to be confused. Im pretty new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.