Class: Admin::RepliesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/admin/replies_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


23
24
25
26
27
28
29
30
31
# File 'app/controllers/admin/replies_controller.rb', line 23

def create
  @reply = Reply.new(params[:reply].permit!)

  if @reply.save
    redirect_to(admin_replies_path, notice: 'Reply was successfully created.')
  else
    render action: 'new'
  end
end

#destroyObject


43
44
45
46
# File 'app/controllers/admin/replies_controller.rb', line 43

def destroy
  @reply = Reply.unscoped.find(params[:id])
  @reply.destroy
end

#editObject


19
20
21
# File 'app/controllers/admin/replies_controller.rb', line 19

def edit
  @reply = Reply.unscoped.find(params[:id])
end

#indexObject


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

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

#newObject


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

def new
  @reply = Reply.new
end

#showObject


7
8
9
10
11
12
13
# File 'app/controllers/admin/replies_controller.rb', line 7

def show
  @reply = Reply.unscoped.find(params[:id])

  if @reply.topic.blank?
    redirect_to admin_replies_path, alert: '帖子已经不存在'
  end
end

#updateObject


33
34
35
36
37
38
39
40
41
# File 'app/controllers/admin/replies_controller.rb', line 33

def update
  @reply = Reply.unscoped.find(params[:id])

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