class Superuser::BaseController
Private Instance Methods
authenticated_superuser()
click to toggle source
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# File lib/generators/superuser/templates/base_controller.rb, line 22 def authenticated_superuser # SET YOUR CONDITION HERE TO PREVENT ACCESSING THE ADMIN AREA FROM ANYONE # example: redirect_to root_url if !current_user || current_user.role != 'admin' end
flash_class(key)
click to toggle source
# File lib/generators/superuser/templates/base_controller.rb, line 44 def flash_class(key) case key when "success" then "alert alert-success" when "warning" then "alert alert-warning" when "notice" then "alert alert-info" when "alert" then "alert alert-danger" end end
run_search(model)
click to toggle source
# File lib/generators/superuser/templates/base_controller.rb, line 27 def run_search(model) search_map = {'gt': '>', 'lt': '<', 'gte': '>=', 'lte': '<=', 'equal': '=', 'like': 'LIKE'} operator = search_map[params[:operator].downcase.to_sym] val = (operator == 'LIKE' ? "%#{params[:search_value]}%" : params[:search_value]) results = pagy( model.where("cast(#{params[:search_field]} as text) #{operator} ?", val) ) flash.now[:warning] = "Sorry! cannot find any #{params[:search_field].upcase} with the value #{operator} '#{params[:search_value]}' :(" if results.blank? return results end