Class: Blogo::Admin::PostsController
- Inherits:
-
BaseController
- Object
- ApplicationController
- Blogo::ApplicationController
- BaseController
- Blogo::Admin::PostsController
- Defined in:
- app/controllers/blogo/admin/posts_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #preview ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/blogo/admin/posts_controller.rb', line 12 def create service = Blogo::CreatePostService.new(blogo_current_user, post_params) if service.create! @post = service.post flash[:notice] = "The post is created" redirect_to blogo_admin_posts_path else @post = service.post render 'new' end end |
#destroy ⇒ Object
41 42 43 44 45 46 47 |
# File 'app/controllers/blogo/admin/posts_controller.rb', line 41 def destroy post = Blogo::Post.find(params[:id]) Blogo::DestroyPostService.new(post).destroy! flash[:notice] = "The post is removed" redirect_to blogo_admin_posts_path end |
#edit ⇒ Object
25 26 27 |
# File 'app/controllers/blogo/admin/posts_controller.rb', line 25 def edit @post = Blogo::Post.find(params[:id]) end |
#index ⇒ Object
4 5 6 |
# File 'app/controllers/blogo/admin/posts_controller.rb', line 4 def index @posts = Blogo::Post.all end |
#new ⇒ Object
8 9 10 |
# File 'app/controllers/blogo/admin/posts_controller.rb', line 8 def new @post = Blogo::Post.new(published: true) end |
#preview ⇒ Object
49 50 51 52 53 54 55 |
# File 'app/controllers/blogo/admin/posts_controller.rb', line 49 def preview @post = Blogo::PreviewPostService.new(blogo_current_user, post_params).preview @meta = {title: @post.title } @tags = Blogo::Tag.all render 'blogo/posts/show', layout: 'blogo/blog' end |
#update ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/blogo/admin/posts_controller.rb', line 29 def update @post = Blogo::Post.find(params[:id]) service = Blogo::UpdatePostService.new(@post, post_params) if service.update! flash[:notice] = "The post is updated" redirect_to blogo_admin_posts_path else render 'edit' end end |