A website template with lots of features, built with ruby on rails.

admin_panel_controller.rb 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. class AdminPanelController < ApplicationController
  2. layout 'admin'
  3. def maintenance_mode
  4. end
  5. def index
  6. redirect_to admin_dashboard_path
  7. end
  8. def dashboard
  9. @users = User.all
  10. @posts = BlogPost.all
  11. @files = Upload.all
  12. end
  13. def posts
  14. @posts = BlogPost.all
  15. end
  16. def contact_messages
  17. @contact_messages = ContactMessage.order('created_at DESC').all
  18. end
  19. def users
  20. @users = User.order('created_at DESC').all
  21. end
  22. def files
  23. @uploads = Upload.all
  24. end
  25. def site_config
  26. @config = Info.first
  27. end
  28. def site_config_update
  29. @config = Info.first
  30. respond_to do |format|
  31. if @config.update(info_params)
  32. format.html { redirect_to admin_config_path, notice: (t 'admin_panel.config_update_success') }
  33. format.json { head :no_content }
  34. else
  35. format.html { render action: 'site_config' }
  36. format.json { render json: @upload.errors, status: :unprocessable_entity }
  37. end
  38. end
  39. end
  40. def make_admin
  41. @user = User.find(params[:id])
  42. if @user.admin == true
  43. @user.admin = false
  44. status = "admin_panel.unmake_admin_success"
  45. else
  46. @user.admin = true
  47. status = "admin_panel.make_admin_success"
  48. end
  49. respond_to do |format|
  50. if @user.save
  51. format.html { redirect_to admin_users_path, notice: (t status) }
  52. format.json { head :no_content }
  53. else
  54. format.html { redirect_to admin_users_path, alert: (t 'admin_panel.make_admin_error') }
  55. format.json { head :no_content }
  56. end
  57. end
  58. end
  59. private
  60. # Never trust parameters from the scary internet, only allow the white list through.
  61. def info_params
  62. params.require(:info).permit(:website_name, :tagline, :contact_email, :default_language, :maintenance_mode, :maintenance_title, :maintenance_message)
  63. end
  64. end