我正在尝试使用此页面中的教程来实现论坛页面!这里的论坛是一个模型。这是控制器代码:
class ForumsController < ApplicationController
before_filter :admin_required, :except => [:index, :show]
def index
@forums = Forum.all
end
def show
@forum = Forum.find(params[:id])
end
def new
@forum = Forum.new
end
def create
@forum = Forum.new(params[:forum])
if @forum.save
redirect_to @forum, :notice => "Successfully created forum."
else
render :action => 'new'
end
end
def edit
@forum = Forum.find(params[:id])
end
def update
@forum = Forum.find(params[:id])
if @forum.update_attributes(params[:forum])
redirect_to @forum, :notice => "Successfully updated forum."
else
render :action => 'edit'
end
end
def destroy
@forum = Forum.find(params[:id])
@forum.destroy
redirect_to forums_url, :notice => "Successfully destroyed forum."
end
end
错误是:
undefined method `all' for Forum:Module
这是论坛模型(models/forum.rb):
class Forum < ActiveRecord::Base
attr_accessible :name, :description
has_many :topics, :dependent => :destroy
#method to find the most recent forum topics
def most_recent_post
topic = Topic.first(:order => 'last_post_at DESC', :conditions => ['forum_id = ?', self.id])
return topic
end
end
我该如何纠正这个错误?我是 ROR 新手,无法找到解决此错误的正确方法。