Class: Effective::PostsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Effective::PostsController
- Defined in:
- app/controllers/effective/posts_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
-
#new ⇒ Object
Public user submit a post functionality.
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/controllers/effective/posts_controller.rb', line 49 def create @post ||= Effective::Post.new(post_params) @post.user = current_user if defined?(current_user) @post.draft = (EffectivePosts.submissions_require_approval == true) EffectivePosts.(self, :create, @post) if @post.save @page_title ||= 'Post Submitted' flash.now[:success] = 'Successfully submitted post' if EffectivePosts.submissions_require_approval @post.send_post_submitted_to_admin! end render :submitted else @page_title ||= 'New Post' flash.now[:danger] = 'Unable to submit post' render action: :new end end |
#destroy ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/controllers/effective/posts_controller.rb', line 102 def destroy @post ||= Effective::Post.find(params[:id]) EffectivePosts.(self, :destroy, @post) if @post.destroy flash[:success] = 'Successfully deleted post' else flash[:danger] = 'Unable to delete post' end redirect_to effective_posts.posts_path end |
#edit ⇒ Object
72 73 74 75 76 77 |
# File 'app/controllers/effective/posts_controller.rb', line 72 def edit @post ||= Effective::Post.find(params[:id]) @page_title ||= 'Edit Post' EffectivePosts.(self, :edit, @post) end |
#index ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/controllers/effective/posts_controller.rb', line 10 def index @posts ||= Effective::Post.posts(user: current_user, category: params[:category]) @posts = @posts.page(params[:page]).per(EffectivePosts.per_page) if params[:category] == 'events' @posts = @posts.reorder(:start_at).where('start_at > ?', Time.zone.now) end if params[:search].present? search = params[:search].permit(EffectivePosts.permitted_params).delete_if { |k, v| v.blank? } @posts = @posts.where(search) if search.present? end EffectivePosts.(self, :index, Effective::Post) @page_title = (params[:page_title] || params[:category] || params[:defaults].try(:[], :category) || 'Posts').titleize end |
#new ⇒ Object
Public user submit a post functionality
42 43 44 45 46 47 |
# File 'app/controllers/effective/posts_controller.rb', line 42 def new @post ||= Effective::Post.new(published_at: Time.zone.now) @page_title = 'New Post' EffectivePosts.(self, :new, @post) end |
#show ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/effective/posts_controller.rb', line 28 def show @posts ||= Effective::Post.posts(user: current_user, category: params[:category], drafts: (params[:edit].to_s == 'true' || params[:preview].to_s == 'true')) @post = @posts.find(params[:id]) if @post.respond_to?(:roles_permit?) raise Effective::AccessDenied unless @post.roles_permit?(current_user) end EffectivePosts.(self, :show, @post) @page_title = @post.title end |
#update ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/controllers/effective/posts_controller.rb', line 79 def update @post ||= Effective::Post.find(params[:id]) draft_was = @post.draft @post.draft = (EffectivePosts.submissions_require_approval == true) EffectivePosts.(self, :update, @post) if @post.update_attributes(post_params) @page_title ||= 'Post Submitted' flash.now[:success] = 'Successfully re-submitted post' if EffectivePosts.submissions_require_approval && draft_was != true @post.send_post_submitted_to_admin! end render :submitted else @page_title ||= 'Edit Post' flash.now[:danger] = 'Unable to update post' render action: :edit end end |