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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:23:36+00:00 2026-05-17T02:23:36+00:00

i have table AuditLog with fields including: audited_id | audited_type That results in data

  • 0

i have table AuditLog with fields including: audited_id | audited_type

That results in data like:
108 | Photo
303 | Comment

What I want to do is create a link to the item, so for the example above:

here is the photo

I’m trying to use a polymorphic_path but am getting an error: “undefined method `model_name’ for Fixnum:Class”

When using:

<%= link_to 'Here she is', polymorphic_path([audited_id, audited_type]) %>

Ideas? Thanks

Updating with code based on the answer by Luke below:

class NewsFeed < ActiveRecord::Base
    default_scope :order => 'news_feeds.created_at DESC'    
    belongs_to :feeded, :polymorphic => true
end

class Note < ActiveRecord::Base
  has_many :newsfeed, :as => :feeded
end

In the partial which is being passed the local storyitem:

<%= link_to 'Here she is', polymorphic_path(storyitem.feeded) %>

The DB migration file, contains the following line for CreateNewsFeeds

  t.references :feeded, :polymorphic => true
  • 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-17T02:23:36+00:00Added an answer on May 17, 2026 at 2:23 am

    You should have a method #auditable (or whatever your polymorphic association is called) on AuditLog objects. If you pass the result of that method to polymorphic_path it will return the correct path for you.

    Update:

    Assuming you have the following associations (or are using acts_as_auditable or something that sets up the relationships for you):

    class AuditLog
      belongs_to :auditable, :polymorphic => true
    end
    
    class AuditedObject
      has_many :audits, :as => :auditable
    end
    

    You’ll be able to call auditable on any instance of AuditLog, and it will return the associated audited object. So you can call

    <%= link_to 'Here she is', polymorphic_path(audit_log.auditable) %>
    

    to get a link to the audited object.

    So, anywhere that you have a polymorphic association in a class, there is an instance method setup with the name of that association that will return the associated object.

    Gosh, I’m hoping that makes sense. Let me know if you need me to clarify it further.

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

Sidebar

Related Questions

I have table of data that is sorted as follows: Item | Sample |
I have table with column Percentage varchar(10) Data in that table is Pecentage 2/10
I have table with data about tasks like Id, Name, Date, WorkerId, VehicleId (and
I have table that uses inline editing with ajax to modify the fields. The
i have table with two fields competition {stateTime, endTime} when i insert to that
I have table with permissions that has few bit fields. I want to group
I have table that has a column of type DateTime, I would like to
I have table with some rows. I would like to create a CSS that
I have table rows like so: <tr class=parent0 row3 data-parent=0> <td>...</td> </tr> <tr class=parent3
I have table with around 70 000 rows. There is 6000 rows that i

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.