diff --git a/app/controllers/ajax/report_controller.rb b/app/controllers/ajax/report_controller.rb new file mode 100644 index 00000000..ee03a461 --- /dev/null +++ b/app/controllers/ajax/report_controller.rb @@ -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 diff --git a/app/views/ajax/report/create.json.jbuilder b/app/views/ajax/report/create.json.jbuilder new file mode 100644 index 00000000..f2c8c8c4 --- /dev/null +++ b/app/views/ajax/report/create.json.jbuilder @@ -0,0 +1,2 @@ +json.partial! 'ajax/shared/status' +json.render @render \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index cf93af44..c1481105 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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