Class: Admin::TopicsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/admin/topics_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#fresh_when, #redirect_back_or_default, #redirect_referrer_or_default, #render_403, #render_404, #render_optional_error_file, #require_user, #set_active_menu, #set_locale, #set_seo_meta, #store_location, #unread_notify_count

Instance Method Details

#createObject


19
20
21
22
23
24
25
26
27
# File 'app/controllers/admin/topics_controller.rb', line 19

def create
  @topic = Topic.new(params[:topic].permit!)

  if @topic.save
    redirect_to(admin_topics_path, notice: 'Topic was successfully created.')
  else
    render action: 'new'
  end
end

#destroyObject


39
40
41
42
43
44
# File 'app/controllers/admin/topics_controller.rb', line 39

def destroy
  @topic = Topic.unscoped.find(params[:id])
  @topic.destroy_by(current_user)

  redirect_to(admin_topics_path)
end

#editObject


15
16
17
# File 'app/controllers/admin/topics_controller.rb', line 15

def edit
  @topic = Topic.unscoped.find(params[:id])
end

#indexObject


3
4
5
# File 'app/controllers/admin/topics_controller.rb', line 3

def index
  @topics = Topic.unscoped.order(id: :desc).includes(:user).paginate page: params[:page], per_page: 30
end

#newObject


11
12
13
# File 'app/controllers/admin/topics_controller.rb', line 11

def new
  @topic = Topic.new
end

#showObject


7
8
9
# File 'app/controllers/admin/topics_controller.rb', line 7

def show
  @topic = Topic.unscoped.find(params[:id])
end

#suggestObject


52
53
54
55
56
57
# File 'app/controllers/admin/topics_controller.rb', line 52

def suggest
  @topic = Topic.unscoped.find(params[:id])
  @topic.update_attribute(:suggested_at, Time.now)
  CacheVersion.topic_last_suggested_at = Time.now
  redirect_to(admin_topics_path, notice: "Topic:#{params[:id]} suggested.")
end

#undestroyObject


46
47
48
49
50
# File 'app/controllers/admin/topics_controller.rb', line 46

def undestroy
  @topic = Topic.unscoped.find(params[:id])
  @topic.update_attribute(:deleted_at, nil)
  redirect_to(admin_topics_path)
end

#unsuggestObject


59
60
61
62
63
64
# File 'app/controllers/admin/topics_controller.rb', line 59

def unsuggest
  @topic = Topic.unscoped.find(params[:id])
  @topic.update_attribute(:suggested_at, nil)
  CacheVersion.topic_last_suggested_at = Time.now
  redirect_to(admin_topics_path, notice: "Topic:#{params[:id]} unsuggested.")
end

#updateObject


29
30
31
32
33
34
35
36
37
# File 'app/controllers/admin/topics_controller.rb', line 29

def update
  @topic = Topic.unscoped.find(params[:id])

  if @topic.update_attributes(params[:topic].permit!)
    redirect_to(admin_topics_path, notice: 'Topic was successfully updated.')
  else
    render action: 'edit'
  end
end