在使用 STI 时,我试图获取特定 :type 的所有页面。
我在 pages_controller.rb 中有一个主类
class PagesController < ApplicationController
def index
@pages = Page.all
end
end
在此之下,我在 pages_controller.rb 中有另一个类
class Blog < Page
def index
@pages = Blog.all
end
end
Blog 类不应该获取所有具有“博客”类型的页面吗?相反,无论类型如何,它都会获取所有页面。我也试过@pages = Page.where(:type => "Blog")
我正在访问 URL http://localhost:3000/blog
这是我的路线
resources :pages do
collection do
get :gallery
get :list
end
end
resources :blog, :controller => :pages