Class: Decidim::DecidimAwesome::Admin::ConstraintsController
- Inherits:
-
ApplicationController
- Object
- Admin::ApplicationController
- ApplicationController
- Decidim::DecidimAwesome::Admin::ConstraintsController
- Includes:
- NeedsAwesomeConfig, Headers::HttpCachingDisabler
- Defined in:
- app/controllers/decidim/decidim_awesome/admin/constraints_controller.rb
Overview
Constraints configuration controller for config keys
Instance Method Summary collapse
Methods included from NeedsAwesomeConfig
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/decidim/decidim_awesome/admin/constraints_controller.rb', line 25 def create @form = form(ConstraintForm).from_params(params, setting: current_setting) CreateConstraint.call(@form) do on(:ok) do |constraint| render json: { id: constraint.id, key: current_setting.var, message: I18n.t("decidim_awesome.admin.constraints.create.success", scope: "decidim"), html: render_to_string(partial: "decidim/decidim_awesome/admin/config/constraints", locals: { key: current_setting.var, constraints: current_setting.constraints }) } end on(:invalid) do || render json: { id: params[:id], key: current_setting.var, message: I18n.t("decidim_awesome.admin.constraints.create.error", scope: "decidim"), error: }, status: :unprocessable_entity end end end |
#destroy ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/controllers/decidim/decidim_awesome/admin/constraints_controller.rb', line 81 def destroy DestroyConstraint.call(constraint) do on(:ok) do render json: { id: params[:id], key: constraint.awesome_config.var, message: I18n.t("decidim_awesome.admin.constraints.destroy.success", scope: "decidim"), html: render_to_string(partial: "decidim/decidim_awesome/admin/config/constraints", locals: { key: constraint.awesome_config.var, constraints: constraint.awesome_config.constraints }) } end on(:invalid) do || render json: { id: params[:id], key: constraint.awesome_config.var, message: I18n.t("decidim_awesome.admin.constraints.destroy.error", scope: "decidim"), error: }, status: :unprocessable_entity end end end |
#new ⇒ Object
21 22 23 |
# File 'app/controllers/decidim/decidim_awesome/admin/constraints_controller.rb', line 21 def new @form = form(ConstraintForm).from_params(filtered_params, setting: current_setting) end |
#show ⇒ Object
17 18 19 |
# File 'app/controllers/decidim/decidim_awesome/admin/constraints_controller.rb', line 17 def show @form = form(ConstraintForm).from_params(constraint.settings.merge(filtered_params)) end |
#update ⇒ Object
53 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 |
# File 'app/controllers/decidim/decidim_awesome/admin/constraints_controller.rb', line 53 def update @form = form(ConstraintForm).from_params(params) UpdateConstraint.call(@form) do on(:ok) do render json: { id: params[:id], key: constraint.awesome_config.var, message: I18n.t("decidim_awesome.admin.constraints.update.success", scope: "decidim"), html: render_to_string(partial: "decidim/decidim_awesome/admin/config/constraints", locals: { key: constraint.awesome_config.var, constraints: constraint.awesome_config.constraints }) } end on(:invalid) do || render json: { id: params[:id], key: constraint.awesome_config.var, message: I18n.t("decidim_awesome.admin.constraints.update.error", scope: "decidim"), error: }, status: :unprocessable_entity end end end |