Class: Blogo::Admin::PostsController
- Inherits:
-
BaseController
- Object
- ApplicationController
- Blogo::ApplicationController
- BaseController
- Blogo::Admin::PostsController
- Defined in:
- app/controllers/blogo/admin/posts_controller.rb
Overview
Responsible for posts management: creation, editing, deletion, preview.
Instance Method Summary collapse
-
#create ⇒ Object
POST /admin/posts.
-
#destroy ⇒ Object
DELETE /admin/posts/:id.
-
#edit ⇒ Object
GET /admin/posts/:id/edit.
-
#index ⇒ Object
GET /admin/posts.
-
#new ⇒ Object
GET /admin/posts/new.
-
#preview ⇒ Object
POST /admin/posts/preview.
-
#update ⇒ Object
PATCH /admin/posts/:id.
Instance Method Details
#create ⇒ Object
POST /admin/posts
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/blogo/admin/posts_controller.rb', line 18 def create service = Blogo::CreatePostService.new(blogo_current_user, post_params) if service.create! @post = service.post flash[:notice] = I18n.translate('blogo.admin.post_created') redirect_to blogo_admin_posts_path else @post = service.post render 'new' end end |
#destroy ⇒ Object
DELETE /admin/posts/:id
53 54 55 56 57 58 59 |
# File 'app/controllers/blogo/admin/posts_controller.rb', line 53 def destroy post = Blogo::Post.where(permalink: params[:id]).first! Blogo::DestroyPostService.new(post).destroy! flash[:notice] = I18n.translate('blogo.admin.post_removed') redirect_to blogo_admin_posts_path end |
#edit ⇒ Object
GET /admin/posts/:id/edit
33 34 35 |
# File 'app/controllers/blogo/admin/posts_controller.rb', line 33 def edit @post = Blogo::Post.where(permalink: params[:id]).first! end |
#index ⇒ Object
GET /admin/posts
6 7 8 |
# File 'app/controllers/blogo/admin/posts_controller.rb', line 6 def index @posts = Blogo::Post.all end |
#new ⇒ Object
GET /admin/posts/new
12 13 14 |
# File 'app/controllers/blogo/admin/posts_controller.rb', line 12 def new @post = Blogo::Post.new(published: true) end |
#preview ⇒ Object
POST /admin/posts/preview
63 64 65 66 67 68 69 70 |
# File 'app/controllers/blogo/admin/posts_controller.rb', line 63 def preview @post = Blogo::PreviewPostService.new(blogo_current_user, post_params).preview = {title: @post.title } @recent_posts = Blogo::Post.published.limit(Blogo.config.recent_posts) if Blogo.config.recent_posts = Blogo::Tag.all render 'blogo/posts/show', layout: 'blogo/blog' end |
#update ⇒ Object
PATCH /admin/posts/:id
39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/blogo/admin/posts_controller.rb', line 39 def update @post = Blogo::Post.where(permalink: params[:id]).first! service = Blogo::UpdatePostService.new(@post, post_params) if service.update! flash[:notice] = I18n.translate('blogo.admin.post_updated') redirect_to blogo_admin_posts_path else render 'edit' end end |