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/blogs_controller.rb | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 app/controllers/admin/blogs_controller.rb (limited to 'app/controllers/admin/blogs_controller.rb') 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 -- cgit 1.4.1