Class: Decidim::Solutions::SolutionsController

Inherits:
ApplicationController show all
Includes:
ApplicationHelper, OrderableSolutions, WithDefaultFilters, WithSdgs, FilterResource, FormFactory, Paginable
Defined in:
app/controllers/decidim/solutions/solutions_controller.rb

Overview

Controller that allows browsing solutions.

Instance Method Summary collapse

Instance Method Details

#createObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/decidim/solutions/solutions_controller.rb', line 45

def create
  enforce_permission_to :create, :solution
  @form = form(Decidim::Solutions::SolutionsForm).from_params(params.merge({ author_id: current_user.id }))

  Decidim::Solutions::CreateSolution.call(@form) do
    on(:ok) do
      flash[:notice] = I18n.t("solutions.create.success", scope: "decidim.solutions")
      redirect_to solutions_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("solutions.create.error", scope: "decidim.solutions")
      render action: "new"
    end
  end
end

#indexObject



24
25
26
27
28
# File 'app/controllers/decidim/solutions/solutions_controller.rb', line 24

def index
  @solutions = search.result
  @solutions = reorder(@solutions)
  @solutions = paginate(@solutions)
end

#newObject



40
41
42
43
# File 'app/controllers/decidim/solutions/solutions_controller.rb', line 40

def new
  enforce_permission_to :create, :solution
  @form = form(Decidim::Solutions::SolutionsForm).instance
end

#showObject



30
31
32
33
34
35
36
37
38
# File 'app/controllers/decidim/solutions/solutions_controller.rb', line 30

def show
  @solution = solution
  if @solution.problem.present?
    @sectorial_scope = sectorial_scope
    @technological_scope = technological_scope
  end
  @sdg_index = sdg_index if @solution.problem.present? || @solution.challenge.present?
  @challenge_scope = challenge_scope
end