Skip to content

Instantly share code, notes, and snippets.

@grooves
Created December 4, 2012 05:25
Show Gist options
  • Save grooves/4200920 to your computer and use it in GitHub Desktop.
Save grooves/4200920 to your computer and use it in GitHub Desktop.
Question 2
# coding: utf-8
class Activity < ActiveRecord::Base
belongs_to :target, polymorphic: true
def message
# return something
end
end
# coding: utf-8
class Publication < ActiveRecord::Base
has_many :target_activities, as: :target, class_name: 'Activity', dependent: :destroy
end
- @publications.each do |pub|
= pub.title
- pub.target_activities.limit(7).each.with_index do |activity, i|
- if i < 6
= activity.message
- else
= "もっと見る"
# coding: utf-8
class SkilltagsControlle < ApplicationController
def show(id)
@skilltag = Skilltag.find id
@publications = @skilltag.publications.all
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment