Paste
Pasted by registered user omemunama ( 10 years ago )
################## model ###############
class Term < ActiveRecord::Base
belongs_to :post
belongs_to :category
end
class Post < ActiveRecord::Base
belongs_to :user
has_many :terms
has_many :categories, :through => :terms
has_many :comments
def to_s
title
end
end
class Category < ActiveRecord::Base
has_many :posts
has_many :posts, :through => :terms
def to_s
title
end
end
################## views ###############
########## categories/show #############
<h1>Category <em><%= @category %></em></h1>
<section class="listing">
<%= render partial: 'posts/post', collection: @category.posts.order('created_at desc') %>
</section>
Revise this Paste
Children: 80000