Class: ForumsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ForumsController
- Defined in:
- app/controllers/forums_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
-
#index ⇒ Object
before_filter :admin?, :except => [:show, :index].
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'app/controllers/forums_controller.rb', line 31 def create @forum.attributes = params[:forum] @forum.save! respond_to do |format| format.html { redirect_to @forum } format.xml { head :created, :location => forum_url(@forum, :format => :xml) } end end |
#destroy ⇒ Object
48 49 50 51 52 53 54 |
# File 'app/controllers/forums_controller.rb', line 48 def destroy @forum.destroy respond_to do |format| format.html { redirect_to forums_path } format.xml { head 200 } end end |
#index ⇒ Object
before_filter :admin?, :except => [:show, :index]
7 8 9 10 11 12 13 14 15 |
# File 'app/controllers/forums_controller.rb', line 7 def index @forums = Forum.order('position') # reset the page of each forum we have visited when we go back to index session[:forum_page] = nil respond_to do |format| format.html format.xml { render :xml => @forums } end end |
#show ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/forums_controller.rb', line 17 def show respond_to do |format| format.html do # keep track of when we last viewed this forum for activity indicators (session[:forums] ||= {})[@forum.id] = Time.now.utc if !current_user.nil? (session[:forum_page] ||= Hash.new(1))[@forum.id] = params[:page].to_i if params[:page] @topics = @forum.topics.paginate :page => params[:page] User.find(:all, :conditions => ['id IN (?)', @topics.collect { |t| t.replied_by }.uniq]) unless @topics.blank? end format.xml { render :xml => @forum } end end |
#update ⇒ Object
40 41 42 43 44 45 46 |
# File 'app/controllers/forums_controller.rb', line 40 def update @forum.update_attributes!(params[:forum]) respond_to do |format| format.html { redirect_to @forum } format.xml { head 200 } end end |