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
23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/comfy/admin/blog/posts_controller.rb', line 23 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
47 48 49 50 51 |
# File 'app/controllers/comfy/admin/blog/posts_controller.rb', line 47 def destroy @post.destroy flash[:success] = t(".deleted") redirect_to action: :index end |
#edit ⇒ Object
33 34 35 |
# File 'app/controllers/comfy/admin/blog/posts_controller.rb', line 33 def edit render end |
#form_fragments ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'app/controllers/comfy/admin/blog/posts_controller.rb', line 53 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]) render( partial: "comfy/admin/cms/fragments/form_fragments", locals: { record: @post, scope: :post }, layout: false ) end |
#index ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'app/controllers/comfy/admin/blog/posts_controller.rb', line 9 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
19 20 21 |
# File 'app/controllers/comfy/admin/blog/posts_controller.rb', line 19 def new render end |
#update ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/comfy/admin/blog/posts_controller.rb', line 37 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 |