reporting things via ajax works now
This commit is contained in:
parent
3f24542410
commit
ce280fffa1
|
@ -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
|
|
@ -0,0 +1,2 @@
|
|||
json.partial! 'ajax/shared/status'
|
||||
json.render @render
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue