module Cytoplasm class Ajax < AbstractController::Base extend ActiveSupport::Concern included do # anything you would want to do in every controller, for example: add a class attribute # class_attribute :class_attribute_available_on_every_controller, instance_writer: false end module ClassMethods # notice: no self.method_name here, because this is being extended because ActiveSupport::Concern was extended end # instance methods to go on every controller go here def self.ajax_success(message=false,data={}) puts "Ajax Success function called!" output = {"status" => "OK"} unless message.is_a? String or message==false data = message message = false end output["message"] = message if message.is_a? String and message!="" data.each {|k,v| output[k] = v if data.key?(k)} unless data.empty? return output.to_json end def self.ajax_error(message=false) puts "Ajax Error function called!" output = {"status" => "Error"} output["message"] = message if message.is_a? String and message != "" return output.to_json abort end end end