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 7590403
In Process

The Archive Base Latest Questions

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

There’s probably a simple answer to this, but I’m lost. I created my first

  • 0

There’s probably a simple answer to this, but I’m lost.

I created my first Polymorphic Association today to create an activity field.

Here’s the activity.rb:

class Activity < ActiveRecord::Base

  belongs_to :trackable, :polymorphic => true

end

In the database for activities, I have the columns:

id
name
trackable_id
trackable_type
created_at
updated_at

Here’s the note.rb:

class Note < ActiveRecord::Base

  has_many :activities, :as => :trackable

  after_create :create_an_activity

  def create_an_activity
    self.activities.build(:name => candidate_id)
  end

end

In my index.html.erb view I have:

<% @activities.each do |activity| %>
  <p>activity.name</p>
<% end >

My question is:

Currently, activity.name in the view is outputting the id because I have :name => candidate_id. A note is created for a candidate. But, what I really want it to output is candidate.full_name (which is in the candidates table). However, this doesn’t work because full_name is not in the notes table. It’s in the candidates table. Is there any way to access that? Candidates has_many notes and a note belongs_to a candidate.

  • 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-30T20:23:35+00:00Added an answer on May 30, 2026 at 8:23 pm

    enjoyed your skill share with Vin a couple months ago!

    I believe what you’re looking for can be accessed by going through the parent association, by calling self -> parent -> attribute:

    def create_an_activity
      self.activities.create(:name => self.candidate.full_name)
    end
    

    Also correct me if i’m wrong, but unless you are calling a save later on, it seems like self.activities.create is what you are looking for instead of .build

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There must be a simple solution to this, but after 4 hours of browsing
There are things like f.call(...) f.apply(...) But then there's this (1, alert)('Zomg what is
There are two popular closure styles in javascript. The first I call anonymous constructor
There is previous little on the google on this subject other than people asking
There are several shading languages available today like GLSL, HLSL, CG, which one to
There was a smbmrx sample code using RDBSS in WDK Vista. But since WDK
There's no Sort() function for IList . Can someoene help me with this? I
There are many tutorials that talk about deleting index.php from the url. But I
There's a lot of reading on self referencing problems, but I can't seem to
There is this strange situation I'm fighting on. I have 3 pages, les call

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.