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
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'app/controllers/admin/posts_controller.rb', line 104 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
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/admin/posts_controller.rb', line 26 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
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/controllers/admin/posts_controller.rb', line 90 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
50 51 52 53 54 55 |
# File 'app/controllers/admin/posts_controller.rb', line 50 def edit @post = Effective::Post.find(params[:id]) @page_title = 'Edit Post' end |
#excerpts ⇒ Object
119 120 121 122 123 124 |
# File 'app/controllers/admin/posts_controller.rb', line 119 def excerpts @posts = Effective::Post.includes(:regions) @page_title = 'Post Excerpts' end |
#index ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/controllers/admin/posts_controller.rb', line 7 def index @page_title = 'Posts' if Gem::Version.new(EffectiveDatatables::VERSION) < Gem::Version.new('3.0') @datatable = Effective::Datatables::Posts.new() else @datatable = EffectivePostsDatatable.new(self) end end |
#new ⇒ Object
19 20 21 22 23 24 |
# File 'app/controllers/admin/posts_controller.rb', line 19 def new @post = Effective::Post.new(published_at: Time.zone.now) @page_title = 'New Post' end |
#update ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/controllers/admin/posts_controller.rb', line 57 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 elsif params[:commit] == 'Save and Duplicate' begin post = @post.duplicate! flash[:success] = 'Successfully saved and duplicated post.' flash[:info] = "You are now editting the duplicated post. This new post has been created as a Draft." rescue => e flash.delete(:success) flash[:danger] = "Unable to duplicate post: #{e.}" end redirect_to effective_posts.edit_admin_post_path(post || @post) 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 |