Module: Decidim::LikeableHelper

Included in:
Blogs::ApplicationHelper, Debates::ApplicationHelper, LikeButtonsCell, LikesController, Meetings::MeetingsHelper, Proposals::ApplicationHelper
Defined in:
decidim-core/app/helpers/decidim/likeable_helper.rb

Overview

A Helper for views with likeable resources.

Instance Method Summary collapse

Instance Method Details

#current_user_can_like?Boolean

Public: Checks if the current user is allowed to like in this step.

Returns true if the current user can like, false otherwise.

Returns:

  • (Boolean)


23
24
25
# File 'decidim-core/app/helpers/decidim/likeable_helper.rb', line 23

def current_user_can_like?
  current_user && likes_enabled? && !likes_blocked?
end

#likes_blocked?Boolean

Public: Checks if likes are blocked in this step.

Returns true if blocked, false otherwise.

Returns:

  • (Boolean)


16
17
18
# File 'decidim-core/app/helpers/decidim/likeable_helper.rb', line 16

def likes_blocked?
  current_settings.likes_blocked
end

#likes_enabled?Boolean

Public: Checks if like are enabled in this step.

Returns true if enabled, false otherwise.

Returns:

  • (Boolean)


9
10
11
# File 'decidim-core/app/helpers/decidim/likeable_helper.rb', line 9

def likes_enabled?
  current_settings.likes_enabled
end

#path_to_create_like(resource) ⇒ Object

produces the path that should be POST to create a like



35
36
37
38
# File 'decidim-core/app/helpers/decidim/likeable_helper.rb', line 35

def path_to_create_like(resource)
  likes_path(resource_id: resource.to_gid.to_param,
             authenticity_token: form_authenticity_token)
end

#path_to_destroy_like(resource) ⇒ Object

Produces the path that should be DELETE to destroy a like.



41
42
43
44
# File 'decidim-core/app/helpers/decidim/likeable_helper.rb', line 41

def path_to_destroy_like(resource)
  like_path(resource.to_gid.to_param,
            authenticity_token: form_authenticity_token)
end

#show_likes_card?Boolean

Public: Checks if the card for likes should be rendered.

Returns true if the likes card should be rendered, false otherwise.

Returns:

  • (Boolean)


30
31
32
# File 'decidim-core/app/helpers/decidim/likeable_helper.rb', line 30

def show_likes_card?
  likes_enabled?
end