我正在尝试使用这个页面的教程(页面链接)实现一个论坛页面!在这里,论坛是一个模型(model)。以下是控制器(controller)代码:
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的新手,无法找到适当的解决方案来解决这个错误。