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
103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/controllers/admin/posts_controller.rb', line 103 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 44 45 |
# 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' 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 elsif params[:commit] == 'Save and View' redirect_to effective_posts.post_path(@post) 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
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/controllers/admin/posts_controller.rb', line 89 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
47 48 49 50 51 52 |
# File 'app/controllers/admin/posts_controller.rb', line 47 def edit @post = Effective::Post.find(params[:id]) @page_title = 'Edit Post' end |
#excerpts ⇒ Object
118 119 120 121 122 123 |
# File 'app/controllers/admin/posts_controller.rb', line 118 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 = EffectivePostsDatatable.new(self) 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
54 55 56 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 |
# File 'app/controllers/admin/posts_controller.rb', line 54 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' 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 View' redirect_to effective_posts.post_path(@post) 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 |