Class: Comfy::Admin::Blog::PostsController
- Inherits:
-
Cms::BaseController
- Object
- Cms::BaseController
- Comfy::Admin::Blog::PostsController
- Defined in:
- app/controllers/comfy/admin/blog/posts_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #form_fragments ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/comfy/admin/blog/posts_controller.rb', line 21 def create @post.save! flash[:success] = t(".created") redirect_to action: :edit, id: @post rescue ActiveRecord::RecordInvalid flash.now[:danger] = t(".create_failure") render action: :new end |
#destroy ⇒ Object
45 46 47 48 49 |
# File 'app/controllers/comfy/admin/blog/posts_controller.rb', line 45 def destroy @post.destroy flash[:success] = t(".deleted") redirect_to action: :index end |
#edit ⇒ Object
31 32 33 |
# File 'app/controllers/comfy/admin/blog/posts_controller.rb', line 31 def edit render end |
#form_fragments ⇒ Object
51 52 53 54 |
# File 'app/controllers/comfy/admin/blog/posts_controller.rb', line 51 def form_fragments @post = @site.blog_posts.find_by(id: params[:id]) || @site.blog_posts.new @post.layout = @site.layouts.find_by(id: params[:layout_id]) end |
#index ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'app/controllers/comfy/admin/blog/posts_controller.rb', line 7 def index return redirect_to action: :new if @site.blog_posts.count.zero? posts_scope = @site.blog_posts .includes(:categories) .for_category(params[:categories]) .order(published_at: :desc) @posts = comfy_paginate(posts_scope) end |
#new ⇒ Object
17 18 19 |
# File 'app/controllers/comfy/admin/blog/posts_controller.rb', line 17 def new render end |
#update ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/comfy/admin/blog/posts_controller.rb', line 35 def update @post.update_attributes!(post_params) flash[:success] = t(".updated") redirect_to action: :edit, id: @post rescue ActiveRecord::RecordInvalid flash.now[:danger] = t(".update_failure") render action: :edit end |