Class: RepliesController

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


6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/replies_controller.rb', line 6

def create
  @reply = Reply.new(reply_params)
  @reply.topic_id = @topic.id
  @reply.user_id = current_user.id

  if @reply.save
    @replies_count = @topic.replies_count + 1
    current_user.read_topic(@topic)
    @msg = t('topics.reply_success')
  else
    @msg = @reply.errors.full_messages.join('<br />')
  end
end

#destroyObject


50
51
52
53
54
55
56
57
# File 'app/controllers/replies_controller.rb', line 50

def destroy
  @reply = Reply.find(params[:id])
  if @reply.destroy
    redirect_to(topic_path(@reply.topic_id), notice: '回帖删除成功。')
  else
    redirect_to(topic_path(@reply.topic_id), alert: '程序异常,删除失败。')
  end
end

#editObject


36
37
38
# File 'app/controllers/replies_controller.rb', line 36

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

#indexObject


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

def index
  last_id = params[:last_id].to_i
  if last_id == 0
    render text: ''
    return
  end

  @replies = Reply.unscoped.where("topic_id = ? and id > ?", @topic.id, last_id).without_body.order(:id).all
  if current_user
    current_user.read_topic(@topic, replies_ids: @replies.collect(&:id))
  end
end

#showObject


33
34
# File 'app/controllers/replies_controller.rb', line 33

def show
end

#updateObject


40
41
42
43
44
45
46
47
48
# File 'app/controllers/replies_controller.rb', line 40

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

  if @reply.update_attributes(reply_params)
    redirect_to(topic_path(@reply.topic_id), notice: '回帖更新成功。')
  else
    render action: 'edit'
  end
end