Class: Decidim::Blogs::Admin::PostsController
- Inherits:
-
ApplicationController
- Object
- Admin::Components::BaseController
- ApplicationController
- Decidim::Blogs::Admin::PostsController
- Defined in:
- app/controllers/decidim/blogs/admin/posts_controller.rb
Overview
This controller allows the create or update a blog.
Instance Method Summary collapse
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/decidim/blogs/admin/posts_controller.rb', line 16 def create :create, :blogpost @form = form(PostForm).from_params(params, current_component:) CreatePost.call(@form) do on(:ok) do flash[:notice] = I18n.t("posts.create.success", scope: "decidim.blogs.admin") redirect_to posts_path end on(:invalid) do flash.now[:alert] = I18n.t("posts.create.invalid", scope: "decidim.blogs.admin") render action: "new" end end end |
#destroy ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/decidim/blogs/admin/posts_controller.rb', line 55 def destroy :destroy, :blogpost, blogpost: post Decidim::Commands::DestroyResource.call(post, current_user) do on(:ok) do flash[:notice] = I18n.t("posts.destroy.success", scope: "decidim.blogs.admin") redirect_to posts_path end end end |
#edit ⇒ Object
33 34 35 36 |
# File 'app/controllers/decidim/blogs/admin/posts_controller.rb', line 33 def edit :update, :blogpost, blogpost: post @form = form(PostForm).from_model(post) end |
#new ⇒ Object
11 12 13 14 |
# File 'app/controllers/decidim/blogs/admin/posts_controller.rb', line 11 def new :create, :blogpost @form = form(PostForm).instance end |
#update ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/decidim/blogs/admin/posts_controller.rb', line 38 def update :update, :blogpost, blogpost: post @form = form(PostForm).from_params(params, current_component:) UpdatePost.call(@form, post) do on(:ok) do flash[:notice] = I18n.t("posts.update.success", scope: "decidim.blogs.admin") redirect_to posts_path end on(:invalid) do flash.now[:alert] = I18n.t("posts.update.invalid", scope: "decidim.blogs.admin") render action: "edit" end end end |