내가 다음과 같은 코드를 가지고many_to_many, sti 및 페이지 매김
class Category < ActiveRecord::Base
has_many :categorizations
has_many :posts, :through => :categorizations
end
class Post < ActiveRecord::Base
has_many :categorizations
has_many :categories, :through => :categorizations
end
class Categorization < ActiveRecord::Base
belongs_to :post
belongs_to :category
end
class NewsArticle < Post
end
좋아, 좋아 보인다. 나는 모든 NewsArticle을 카테고리
@news_articles = NewsArticle.paginate_by_category_id params[:category],
:page => params[:page], :per_page => 10,
:order => 'posts.created_at DESC'
에서 얻으려고하고
NoMethodError in News articlesController#category
undefined method `find_all_by_category' for #<Class:0x103cb05d0>
이 문제를 해결하려면 어떻게해야합니까?
) 감사합니다 :) :)하지만 불행히도 카테고리 모델이 friendly_id (http://github.com/norman/friendly_id) 아래에 있으면 게시물을 찾을 수 없습니다. ( 추신 : 작은 예제 수정 - : 조건 => [ 'categories.id =?', category_id] –
있습니다. 귀하의 예제를 조금 업데이트했는데 이제는 잘 작동합니다. @category = category.find params [: category] @news_articles = NewsArticle.newest.by_category ..... –