Class: Decidim::Blogs::PostsController
- Inherits:
-
ApplicationController
- Object
- Components::BaseController
- ApplicationController
- Decidim::Blogs::PostsController
- Includes:
- FormFactory, IconHelper, Flaggable, Paginable
- Defined in:
- app/controllers/decidim/blogs/posts_controller.rb
Overview
Exposes the blog resource so users can view them
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/decidim/blogs/posts_controller.rb', line 27 def create :create, :blogpost @form = form(Decidim::Blogs::PostForm).from_params(params, current_component: current_component) CreatePost.call(@form) do on(:ok) do |new_post| flash[:notice] = I18n.t("posts.create.success", scope: "decidim.blogs.admin") redirect_to post_path(new_post) end on(:invalid) do flash.now[:alert] = I18n.t("posts.create.invalid", scope: "decidim.blogs.admin") render action: "new", status: :unprocessable_entity end end end |
#destroy ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/controllers/decidim/blogs/posts_controller.rb', line 66 def destroy :destroy, :blogpost, blogpost: post Decidim.traceability.perform_action!("delete", post, current_user) do post.destroy! end flash[:notice] = I18n.t("posts.destroy.success", scope: "decidim.blogs.admin") redirect_to posts_path end |
#edit ⇒ Object
44 45 46 47 |
# File 'app/controllers/decidim/blogs/posts_controller.rb', line 44 def edit :update, :blogpost, blogpost: post @form = form(PostForm).from_model(post) end |
#index ⇒ Object
16 |
# File 'app/controllers/decidim/blogs/posts_controller.rb', line 16 def index; end |
#new ⇒ Object
22 23 24 25 |
# File 'app/controllers/decidim/blogs/posts_controller.rb', line 22 def new :create, :blogpost @form = form(Decidim::Blogs::PostForm).instance end |
#show ⇒ Object
18 19 20 |
# File 'app/controllers/decidim/blogs/posts_controller.rb', line 18 def show raise ActionController::RoutingError, "Not Found" unless post end |
#update ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/decidim/blogs/posts_controller.rb', line 49 def update :update, :blogpost, blogpost: post @form = form(PostForm).from_params(params, current_component: current_component) UpdatePost.call(@form, post) do on(:ok) do |post| flash[:notice] = I18n.t("posts.update.success", scope: "decidim.blogs.admin") redirect_to post_path(post) end on(:invalid) do flash.now[:alert] = I18n.t("posts.update.invalid", scope: "decidim.blogs.admin") render action: "edit", status: :unprocessable_entity end end end |