次のフィールドを持つテーブル AuditLog があります。監査済み_タイプ
その結果、次のようなデータが得られます。写真 303 | コメント
私がやりたいことは、アイテムへのリンクを作成することなので、上記の例では:
ここに写真があります
polymorphic_path を使用しようとしていますが、エラーが発生します:「Fixnum:Class の未定義メソッド `model_name'」
使用時:
<%= link_to 'Here she is', polymorphic_path([audited_id, audited_type]) %>
アイデア?ありがとう
以下のルークの回答に基づいたコードで更新します。
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) %>
DB 移行ファイルには、CreateNewsFeeds の次の行が含まれています。
t.references :feeded, :polymorphic => true