Class: EducodeSales::ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/educode_sales/application_controller.rb

Instance Method Summary collapse

Instance Method Details

#authenticate_adminObject



26
27
28
29
30
# File 'app/controllers/educode_sales/application_controller.rb', line 26

def authenticate_admin
  unless current_user&.is_admin
    redirect_to no_permission_path
  end
end

#authenticate_requestObject



18
19
20
21
22
23
24
# File 'app/controllers/educode_sales/application_controller.rb', line 18

def authenticate_request
  if current_user
    current_user.(request)
  else
    redirect_to 
  end
end

#current_userObject



14
15
16
# File 'app/controllers/educode_sales/application_controller.rb', line 14

def current_user
  @current_admin ||= Staff.find_by_id(session[:admin_id])
end

#filterObject



32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/educode_sales/application_controller.rb', line 32

def filter
  params[:check] = params[:check] == "true" ? 0:1
  begin
    filter = Filter.find_or_create_by!(staff_id: @current_admin.id, clazz: params[:type])
    filter.extras["#{params[:name]}"] = params[:check]
    filter.save!
    render json: {success: true ,hidden: params[:check]}
  rescue => e
    render_failure("操作失败")
  end
end

#render_failure(msg) ⇒ Object



10
11
12
# File 'app/controllers/educode_sales/application_controller.rb', line 10

def render_failure(msg)
  render json: { success: false, msg: msg.is_a?(String) ? msg : msg.errors.full_messages.join(",") }, status: 403
end

#render_successObject



6
7
8
# File 'app/controllers/educode_sales/application_controller.rb', line 6

def render_success
  render json: { success: true }
end