我有表 AuditLog 字段包括:audited_id | 审核类型
这会产生如下数据:108 | 照片 303 | 评论
我想要做的是创建一个指向该项目的链接,因此对于上面的示例:
这是照片
我正在尝试使用多态路径,但出现错误:“Fixnum:Class 的未定义方法 `model_name'”
使用时:
<%= link_to 'Here she is', polymorphic_path([audited_id, audited_type]) %>
想法?谢谢
根据下面 Luke 的回答更新代码:
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
在被传递的局部故事项目中:
<%= link_to 'Here she is', polymorphic_path(storyitem.feeded) %>
数据库迁移文件,包含 CreateNewsFeeds 的以下行
t.references :feeded, :polymorphic => true