Class: Decidim::FollowsController

Inherits:
ApplicationController show all
Includes:
FormFactory
Defined in:
decidim-core/app/controllers/decidim/follows_controller.rb

Instance Method Summary collapse

Methods included from UserBlockedChecker

#check_user_block_status, #check_user_not_blocked

Methods included from NeedsSnippets

#snippets

Methods included from HttpCachingDisabler

#disable_http_caching

Methods included from HasStoredPath

#skip_store_location?, #store_current_location

Methods included from RegistersPermissions

register_permissions

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#createObject


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'decidim-core/app/controllers/decidim/follows_controller.rb', line 25

def create
  @form = form(Decidim::FollowForm).from_params(params)
  @inline = params[:follow][:inline] == "true"
  enforce_permission_to :create, :follow

  CreateFollow.call(@form, current_user) do
    on(:ok) do
      render :update_button
    end

    on(:invalid) do
      render json: { error: I18n.t("follows.create.error", scope: "decidim") }, status: :unprocessable_entity
    end
  end
end

#destroyObject


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'decidim-core/app/controllers/decidim/follows_controller.rb', line 9

def destroy
  @form = form(Decidim::FollowForm).from_params(params)
  @inline = params[:follow][:inline] == "true"
  enforce_permission_to :delete, :follow, follow: @form.follow

  DeleteFollow.call(@form, current_user) do
    on(:ok) do
      render :update_button
    end

    on(:invalid) do
      render json: { error: I18n.t("follows.destroy.error", scope: "decidim") }, status: :unprocessable_entity
    end
  end
end

#resourceObject


41
42
43
44
45
# File 'decidim-core/app/controllers/decidim/follows_controller.rb', line 41

def resource
  @resource ||= GlobalID::Locator.locate_signed(
    params[:follow][:followable_gid]
  )
end