81 lines
2.4 KiB
Ruby
81 lines
2.4 KiB
Ruby
# encoding: utf-8
|
|
class DiscussesController < ApplicationController
|
|
include ApplicationHelper
|
|
before_filter :find_dis_object, :except => [:destroy]
|
|
before_filter :find_discuss, :only => [:destroy]
|
|
|
|
def create
|
|
if @model
|
|
if params[:reply_id].blank?
|
|
notes = User.current.show_name.to_s + " 评论了你发布的实训:<a href='#{shixun_discuss_shixun_path(@model)}'>#{params[:content]}</a>"
|
|
@model.discusses << Discuss.new(:content => params[:content], :user_id => User.current.id, :praise_count => 0, :challenge_id => params[:challenge_id])
|
|
JournalsForMessage.create(
|
|
:jour_id => @model.user_id,
|
|
:jour_type => "Principal",
|
|
:user_id => User.current.id,
|
|
:reply_id => 0,
|
|
:is_readed => 0,
|
|
:private => 1,
|
|
:notes => notes
|
|
)
|
|
else
|
|
notes = User.current.show_name.to_s + " 评论了你的回复:<a href='#{shixun_discuss_shixun_path(@model)}'>#{params[:content]}</a>"
|
|
user_id = Discuss.find(params[:reply_id]).try(:user_id)
|
|
@model.discusses << Discuss.new(
|
|
:content => params[:content],
|
|
:user_id => User.current.id,
|
|
:parent_id => params[:reply_id],
|
|
:root_id => params[:reply_id],
|
|
:praise_count => 0,
|
|
:challenge_id => params[:challenge_id]
|
|
)
|
|
JournalsForMessage.create(
|
|
:jour_id => user_id,
|
|
:jour_type => "Principal",
|
|
:user_id => User.current.id,
|
|
:reply_id => 0,
|
|
:is_readed => 0,
|
|
:private => 1,
|
|
:notes => notes
|
|
)
|
|
end
|
|
|
|
|
|
if params[:dis_type] == "Shixun"
|
|
redirect_to shixun_discuss_shixun_path(@model, :challenge_id => params[:challenge_id])
|
|
end
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
if @discuss
|
|
if @discuss.dis_type == "Shixun"
|
|
@shixun = @discuss.dis
|
|
end
|
|
@discuss.destroy
|
|
@game_challenge = Challenge.find(params[:challenge_id])
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def find_discuss
|
|
@discuss = Discuss.find params[:id]
|
|
rescue ActiveRecord::RecordNotFound
|
|
render_404
|
|
end
|
|
|
|
def find_dis_object
|
|
unless params[:dis_id] && params[:dis_type]
|
|
render_404
|
|
else
|
|
case params[:dis_type]
|
|
when 'Shixun'
|
|
@model = Shixun.find params[:dis_id]
|
|
end
|
|
end
|
|
rescue ActiveRecord::RecordNotFound
|
|
render_404
|
|
end
|
|
end
|