mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 14:29:53 +01:00
reporting things via ajax works now
This commit is contained in:
parent
3f24542410
commit
ce280fffa1
3 changed files with 35 additions and 0 deletions
32
app/controllers/ajax/report_controller.rb
Normal file
32
app/controllers/ajax/report_controller.rb
Normal 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
|
2
app/views/ajax/report/create.json.jbuilder
Normal file
2
app/views/ajax/report/create.json.jbuilder
Normal file
|
@ -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 a new issue