現在、以下のようにタグと記事を多対多で実装しています。
article.rb
ruby
1class Article < ActiveRecord::Base 2 has_many :article_tags 3 has_many :tags, through: :article_tags 4end
tag.rb
ruby
1class Tag < ActiveRecord::Base 2 has_many :article_tags 3 has_many :articles, through: :article_tags 4end
article_tag.rb
ruby
1class ArticleTag < ActiveRecord::Base 2 belongs_to :article 3 belongs_to :tag 4end
上記モデルでtagのshowコントローラー内で取得したarticleに対してページネーションをしたいです。
現在は以下のように書いていますが、ページネーションが正常機能しません。
controller/show.rb
ruby
1class TagsController < ApplicationController 2 def show 3 @articles = @tag.articles.page(params[:page]).per(8).order("created_at DESC") 4 end 5end 6 7
tag/show.html.erb
ruby
1<%= paginate(@articles) %>
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/20 10:16 編集
2017/04/20 10:36
2017/04/20 11:45
2017/04/20 11:58
2017/04/20 23:16
2017/04/21 02:17