我正在嘗試使用本教程page來實現論壇頁面。這裏論壇是一個模型。這是控制器代碼:rails - 未定義的方法全部用於論壇:模塊
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
下面是論壇車型(型號/ 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新手,無法找到適合此錯誤的解決方案。
請提供您的論壇模型的源代碼 –
重做第4步。論壇不是模塊,而是應用/模型中的模型 – TheIrishGuy
@ThelrishGuy對於問題中的錯誤感到抱歉,我按照指定的方式完成了它。 – trialError