reporting things via ajax works now

This commit is contained in:
nilsding 2014-12-28 19:55:50 +01:00
parent 3f24542410
commit ce280fffa1
3 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,32 @@
class Ajax::ReportController < ApplicationController
def create
params.require :id
params.require :type
@status = :err
@success = false
if current_user.nil?
@message = "login required"
return
end
unless %w(answer comment question user).include? params[:type]
@message = "unknown type"
return
end
object = params[:type].strip.capitalize.constantize.find params[:id]
if object.nil?
@message = "Could not find #{params[:type]}"
return
end
current_user.report object
@status = :okay
@message = "#{params[:type].capitalize} reported. A moderator will decide what happens with the #{params[:type]}."
@success = true
end
end

View File

@ -0,0 +1,2 @@
json.partial! 'ajax/shared/status'
json.render @render

View File

@ -62,6 +62,7 @@ Rails.application.routes.draw do
match '/create_smile', to: 'smile#create', via: :post, as: :create_smile
match '/destroy_smile', to: 'smile#destroy', via: :post, as: :destroy_smile
match '/create_comment', to: 'comment#create', via: :post, as: :create_comment
match '/report', to: 'report#create', via: :post, as: :report
end
match '/public', to: 'public#index', via: :get, as: :public_timeline