some code

Ruby code posted by sdf
created at 21 Mar 22:44

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
class ForumsController < ApplicationController
  before_filter :admin_required, :except => [:index, :show]

  # GET /forums
  # GET /forums.xml
  def index
    # reset the page of each forum we have visited when we go back to index
    session[:forums_page] = nil

    @forums = current_site.ordered_forums

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @forums }
    end
  end

  # GET /forums/1
  # GET /forums/1.xml
  def show
    @forum = current_site.forums.find_by_permalink(params[:id])
    (session[:forums] ||= {})[@forum.id] = Time.now.utc
    (session[:forums_page] ||= Hash.new(1))[@forum.id] = current_page if current_page > 1

    respond_to do |format|
      format.html do # show.html.erb
        @topics = @forum.topics.paginate :page => current_page
      end
      format.xml  { render :xml => @forum }
    end
  end

  # GET /forums/new
  # GET /forums/new.xml
  def new
    @forum = Forum.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @forum }
    end
  end

  # GET /forums/1/edit
  def edit
    @forum = current_site.forums.find_by_permalink(params[:id])
  end

  # POST /forums
  # POST /forums.xml
  def create
    @forum = current_site.forums.build(params[:forum])

    respond_to do |format|
      if @forum.save
        flash[:notice] = I18n.t 'txt.forum_created', :default => 'Forum was successfully created.'
        format.html { redirect_to(@forum) }
        format.xml  { render :xml => @forum, :status => :created, :location => @forum }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @forum.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /forums/1
  # PUT /forums/1.xml
  def update
    @forum = current_site.forums.find_by_permalink(params[:id])

    respond_to do |format|
      if @forum.update_attributes(params[:forum])
        flash[:notice] = I18n.t 'txt.forum_updated', :default => 'Forum was successfully updated.'
        format.html { redirect_to(@forum) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @forum.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /forums/1
  # DELETE /forums/1.xml
  def destroy
    @forum = current_site.forums.find_by_permalink(params[:id])
    @forum.destroy

    respond_to do |format|
      format.html { redirect_to(forums_path) }
      format.xml  { head :ok }
    end
  end
end
2.59 KB in 4 ms with coderay