Class: Admin::PostsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Admin::PostsController
- Defined in:
- app/controllers/admin/posts_controller.rb
Instance Method Summary collapse
- #approve ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #excerpts ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #update ⇒ Object
Instance Method Details
#approve ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/controllers/admin/posts_controller.rb', line 88 def approve @post = Effective::Post.find(params[:id]) @page_title = 'Approve Post' if @post.update_attributes(draft: false) flash[:success] = 'Successfully approved post. It is now displayed on the website.' else flash[:danger] = "Unable to approve post: #{@post.errors..join(', ')}" end redirect_to(:back) rescue redirect_to(effective_posts.admin_posts_path) end |
#create ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/admin/posts_controller.rb', line 21 def create @post = Effective::Post.new(post_params) @post.user = current_user if defined?(current_user) @page_title = 'New Post' if @post.save if params[:commit] == 'Save and Edit Content' && defined?(EffectiveRegions) redirect_to effective_regions.edit_path(effective_posts.post_path(@post), :exit => effective_posts.edit_admin_post_path(@post)) elsif params[:commit] == 'Save and Add New' flash[:success] = 'Successfully created post' redirect_to effective_posts.new_admin_post_path else flash[:success] = 'Successfully created post' redirect_to effective_posts.edit_admin_post_path(@post) end else flash.now[:danger] = 'Unable to create post' render :action => :new end end |
#destroy ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/controllers/admin/posts_controller.rb', line 74 def destroy @post = Effective::Post.find(params[:id]) if @post.destroy flash[:success] = 'Successfully deleted post' else flash[:danger] = 'Unable to delete post' end redirect_to effective_posts.admin_posts_path end |
#edit ⇒ Object
45 46 47 48 49 50 |
# File 'app/controllers/admin/posts_controller.rb', line 45 def edit @post = Effective::Post.find(params[:id]) @page_title = 'Edit Post' end |
#excerpts ⇒ Object
103 104 105 106 107 108 |
# File 'app/controllers/admin/posts_controller.rb', line 103 def excerpts @posts = Effective::Post.includes(:regions) @page_title = 'Post Excerpts' end |
#index ⇒ Object
7 8 9 10 11 12 |
# File 'app/controllers/admin/posts_controller.rb', line 7 def index @page_title = 'Posts' @datatable = Effective::Datatables::Posts.new() end |
#new ⇒ Object
14 15 16 17 18 19 |
# File 'app/controllers/admin/posts_controller.rb', line 14 def new @post = Effective::Post.new(published_at: Time.zone.now) @page_title = 'New Post' end |
#update ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/controllers/admin/posts_controller.rb', line 52 def update @post = Effective::Post.find(params[:id]) @page_title = 'Edit Post' if @post.update_attributes(post_params) if params[:commit] == 'Save and Edit Content' && defined?(EffectiveRegions) redirect_to effective_regions.edit_path(effective_posts.post_path(@post), :exit => effective_posts.edit_admin_post_path(@post)) elsif params[:commit] == 'Save and Add New' flash[:success] = 'Successfully updated post' redirect_to effective_posts.new_admin_post_path else flash[:success] = 'Successfully updated post' redirect_to effective_posts.edit_admin_post_path(@post) end else flash.now[:danger] = 'Unable to update post' render :action => :edit end end |