From e47e83cf6bded3d1924b4d500193e7876833ef83 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 2 Jul 2017 13:03:43 -0400 Subject: Created admin panel Currently allows you to create and edit blogs, including associated records. Uses a WYSIWYG editor that allows uploading images. Also included jQuery :( --- app/controllers/admin/admin_controller.rb | 5 +++ app/controllers/admin/blogs_controller.rb | 52 +++++++++++++++++++++++++++ app/controllers/admin/dashboard_controller.rb | 12 +++++++ 3 files changed, 69 insertions(+) create mode 100644 app/controllers/admin/admin_controller.rb create mode 100644 app/controllers/admin/blogs_controller.rb create mode 100644 app/controllers/admin/dashboard_controller.rb (limited to 'app/controllers/admin') diff --git a/app/controllers/admin/admin_controller.rb b/app/controllers/admin/admin_controller.rb new file mode 100644 index 0000000..400b02d --- /dev/null +++ b/app/controllers/admin/admin_controller.rb @@ -0,0 +1,5 @@ +class Admin::AdminController < ApplicationController + before_action :authenticate_user! + + layout "admin" +end diff --git a/app/controllers/admin/blogs_controller.rb b/app/controllers/admin/blogs_controller.rb new file mode 100644 index 0000000..fa46ab8 --- /dev/null +++ b/app/controllers/admin/blogs_controller.rb @@ -0,0 +1,52 @@ +class Admin::BlogsController < Admin::AdminController + before_action :set_section + + def index + @blogs = Blog.order(created_at: :desc) + end + + def new + @blog = Blog.new + end + + def create + @blog = Blog.new(blog_params) + + if @blog.save + flash.notice = "Blog created successfully!" + + render :edit + else + flash.alert = "Error creating blog." + + render :new + end + end + + def edit + @blog = Blog.find(params[:id]) + end + + def update + @blog = Blog.find(params[:id]) + + if @blog.update_attributes(blog_params) + flash.notice = "Blog updated successfully!" + else + flash.alert = "Error updating blog." + end + + render :edit + end + + private + + def blog_params + params.require(:blog).permit(:title, :body, :slug, records_attributes: [:description, :_destroy]) + end + + def set_section + @section = "blogs" + end + +end diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb new file mode 100644 index 0000000..6d0e6bb --- /dev/null +++ b/app/controllers/admin/dashboard_controller.rb @@ -0,0 +1,12 @@ +class Admin::DashboardController < Admin::AdminController + before_action :set_section + + def index + end + + private + + def set_section + @section = "dashboard" + end +end -- cgit 1.4.1