application_controller.rb 881 B

123456789101112131415161718192021222324252627
  1. # All Administrate controllers inherit from this `Admin::ApplicationController`,
  2. # making it the ideal place to put authentication logic or other
  3. # before_actions.
  4. #
  5. # If you want to add pagination or other controller-level concerns,
  6. # you're free to overwrite the RESTful controller actions.
  7. module Admin
  8. class ApplicationController < Administrate::ApplicationController
  9. before_action :authenticate_admin
  10. before_action :default_params
  11. def authenticate_admin
  12. redirect_to '/', alert: 'Not authorized.' unless user_signed_in? && current_user.admin?
  13. end
  14. def default_params
  15. params[:order] ||= "created_at"
  16. params[:direction] ||= "desc"
  17. end
  18. # Override this value to specify the number of elements to display at a time
  19. # on index pages. Defaults to 20.
  20. # def records_per_page
  21. # params[:per_page] || 20
  22. # end
  23. end
  24. end