Class: SimpleForum::Admin::ForumsController

Inherits:
BaseController show all
Defined in:
app/controllers/simple_forum/admin/forums_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/simple_forum/admin/forums_controller.rb', line 44

def create
  success = resource.save

  respond_with([:admin, resource]) do |format|
    format.html do
      if success
        redirect_to [:admin, resource]
      else
        render :new
      end
    end
  end
end

#destroyObject



72
73
74
75
76
# File 'app/controllers/simple_forum/admin/forums_controller.rb', line 72

def destroy
  resource.destroy

  respond_with([:admin, resource])
end

#editObject



34
35
36
37
# File 'app/controllers/simple_forum/admin/forums_controller.rb', line 34

def edit

  respond_with([:admin, resource])
end

#indexObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/simple_forum/admin/forums_controller.rb', line 16

def index
  @categories = SimpleForum::Category.default_order.includes({:forums => [{:recent_post => [:user, :topic]}, :moderators]})

  @forums = SimpleForum::Forum.default_order.includes({:recent_post => [:user, :topic]}, :moderators)
  @forums_by_category = @categories.inject(ActiveSupport::OrderedHash.new) { |h, c| h[c] = []; h }
  @forums.each do |f|
    (@forums_by_category[@categories.detect { |c| c.try(:id) == f.category_id }] ||= []) << f
  end
  @forums_by_category.reject! { |c, forums| forums.blank? }

  respond_with(@forums)
end

#newObject



39
40
41
42
# File 'app/controllers/simple_forum/admin/forums_controller.rb', line 39

def new

  respond_with([:admin, resource])
end

#search_usersObject



5
6
7
8
9
10
11
12
13
14
# File 'app/controllers/simple_forum/admin/forums_controller.rb', line 5

def search_users
  user_class = instance_eval(&SimpleForum.invoke(:user_class))
  @users = user_class.where(["#{user_class.quoted_table_name}.email LIKE ?", "%#{params[:user_name_like].to_s.gsub(/[\%\_]/) { |m| "\\#{m}" }}%"]).limit(16)

  respond_to do |format|
    format.json do
      render :json => @users.inject({}) { |hash, u| hash[u.id] = u.name; hash }
    end
  end
end

#showObject



29
30
31
32
# File 'app/controllers/simple_forum/admin/forums_controller.rb', line 29

def show

  respond_with([:admin, resource])
end

#updateObject



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/simple_forum/admin/forums_controller.rb', line 58

def update
  success = resource.update_attributes(params[:forum])

  respond_with([:admin, resource]) do |format|
    format.html do
      if success
        redirect_to [:admin, resource]
      else
        render :edit
      end
    end
  end
end