Sha256: e08699091940195eafb61cee78efe0869d081c1d71f3b563b0df9fb75556f626
Contents?: true
Size: 1019 Bytes
Versions: 12
Compression:
Stored size: 1019 Bytes
Contents
module RemoteRequestManager extend ActiveSupport::Concern PATH_TO_JS_FILE = "shopapp/modal_errors" included do end class_methods do end def redirect_remote_request(notice, args = {}) respond_to do |format| format.html { redirect_to redirect_path(args), success: notice } format.js do flash[:success] = notice render js: "window.location='#{redirect_path(args)}'" end end end def rescue_remote_request(error) Rails.logger.error error.message Rails.logger.error error.backtrace.join("\n") if error.instance_of?(ActiveRecord::RecordInvalid) respond_to_js(error.record.errors.messages) else respond_to_js(error) end end private def respond_to_js(error_message) flash.now[:danger] = error_message respond_to do |format| format.js do render PATH_TO_JS_FILE, locals: { flash: flash } end end end def redirect_path(args) args[:to].presence || request.referer || root_path end end
Version data entries
12 entries across 12 versions & 1 rubygems