50 lines
1.4 KiB
Ruby
50 lines
1.4 KiB
Ruby
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?
|
|
@model.discusses << Discuss.new(:content => params[:content], :user_id => User.current.id, :praise_count => 0, :challenge_id => params[:challenge_id])
|
|
else
|
|
@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])
|
|
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
|