diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-07-02 13:03:43 -0400 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-07-02 13:03:43 -0400 |
| commit | e47e83cf6bded3d1924b4d500193e7876833ef83 (patch) | |
| tree | 058f011637e67455dcd8451fbfa784b5883c6f69 /app/controllers | |
| parent | 528ccde8915cd1ed7a39e137dd4d98869797956a (diff) | |
| download | thoughts-e47e83cf6bded3d1924b4d500193e7876833ef83.tar.gz thoughts-e47e83cf6bded3d1924b4d500193e7876833ef83.tar.bz2 thoughts-e47e83cf6bded3d1924b4d500193e7876833ef83.zip | |
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 :(
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/admin/admin_controller.rb | 5 | ||||
| -rw-r--r-- | app/controllers/admin/blogs_controller.rb | 52 | ||||
| -rw-r--r-- | app/controllers/admin/dashboard_controller.rb | 12 | ||||
| -rw-r--r-- | app/controllers/entries_controller.rb | 21 |
4 files changed, 70 insertions, 20 deletions
| 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 @@ | |||
| 1 | class Admin::AdminController < ApplicationController | ||
| 2 | before_action :authenticate_user! | ||
| 3 | |||
| 4 | layout "admin" | ||
| 5 | 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 @@ | |||
| 1 | class Admin::BlogsController < Admin::AdminController | ||
| 2 | before_action :set_section | ||
| 3 | |||
| 4 | def index | ||
| 5 | @blogs = Blog.order(created_at: :desc) | ||
| 6 | end | ||
| 7 | |||
| 8 | def new | ||
| 9 | @blog = Blog.new | ||
| 10 | end | ||
| 11 | |||
| 12 | def create | ||
| 13 | @blog = Blog.new(blog_params) | ||
| 14 | |||
| 15 | if @blog.save | ||
| 16 | flash.notice = "Blog created successfully!" | ||
| 17 | |||
| 18 | render :edit | ||
| 19 | else | ||
| 20 | flash.alert = "Error creating blog." | ||
| 21 | |||
| 22 | render :new | ||
| 23 | end | ||
| 24 | end | ||
| 25 | |||
| 26 | def edit | ||
| 27 | @blog = Blog.find(params[:id]) | ||
| 28 | end | ||
| 29 | |||
| 30 | def update | ||
| 31 | @blog = Blog.find(params[:id]) | ||
| 32 | |||
| 33 | if @blog.update_attributes(blog_params) | ||
| 34 | flash.notice = "Blog updated successfully!" | ||
| 35 | else | ||
| 36 | flash.alert = "Error updating blog." | ||
| 37 | end | ||
| 38 | |||
| 39 | render :edit | ||
| 40 | end | ||
| 41 | |||
| 42 | private | ||
| 43 | |||
| 44 | def blog_params | ||
| 45 | params.require(:blog).permit(:title, :body, :slug, records_attributes: [:description, :_destroy]) | ||
| 46 | end | ||
| 47 | |||
| 48 | def set_section | ||
| 49 | @section = "blogs" | ||
| 50 | end | ||
| 51 | |||
| 52 | 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 @@ | |||
| 1 | class Admin::DashboardController < Admin::AdminController | ||
| 2 | before_action :set_section | ||
| 3 | |||
| 4 | def index | ||
| 5 | end | ||
| 6 | |||
| 7 | private | ||
| 8 | |||
| 9 | def set_section | ||
| 10 | @section = "dashboard" | ||
| 11 | end | ||
| 12 | end | ||
| diff --git a/app/controllers/entries_controller.rb b/app/controllers/entries_controller.rb index 366de53..14d779a 100644 --- a/app/controllers/entries_controller.rb +++ b/app/controllers/entries_controller.rb | |||
| @@ -1,26 +1,7 @@ | |||
| 1 | class EntriesController < ApplicationController | 1 | class EntriesController < ApplicationController |
| 2 | before_action :authenticate_user!, only: [:edit, :update] | ||
| 3 | 2 | ||
| 4 | def show | 3 | def show |
| 5 | @entry = Entry.where(slug: params[:slug]).first | 4 | @entry = Entry.find_by_slug(params[:slug]) |
| 6 | end | 5 | end |
| 7 | 6 | ||
| 8 | def edit | ||
| 9 | @entry = Entry.where(slug: params[:slug]).first | ||
| 10 | end | ||
| 11 | |||
| 12 | def update | ||
| 13 | @entry = Entry.where(slug: params[:slug]).first | ||
| 14 | |||
| 15 | if @entry.update_attributes(entry_params) | ||
| 16 | flash.notice = "" | ||
| 17 | end | ||
| 18 | end | ||
| 19 | |||
| 20 | private | ||
| 21 | |||
| 22 | def entry_params | ||
| 23 | params.require(:blog).permit(:title, :body, :slug) | ||
| 24 | end | ||
| 25 | |||
| 26 | end | 7 | end |
