Module: VoteFu::VotesHelper
- Defined in:
- app/helpers/vote_fu/votes_helper.rb
Instance Method Summary collapse
-
#current_vote_direction(voteable, options = {}) ⇒ Symbol?
Returns the current vote direction for a voter on a voteable.
-
#downvote_button(voteable, options = {}) ⇒ Object
Renders a standalone downvote button.
-
#like_button(voteable, options = {}) ⇒ Object
Renders a like button (upvote-only, social media style).
-
#upvote_button(voteable, options = {}) ⇒ Object
Renders a standalone upvote button.
-
#vote_count(voteable, options = {}) ⇒ Object
Renders the vote count for a voteable.
-
#vote_dom_id(voteable, suffix = :widget, scope: nil) ⇒ String
Returns the DOM ID for a voteable's widget.
-
#vote_widget(voteable, options = {}) ⇒ Object
Renders the full vote widget with upvote/downvote buttons and count.
-
#voted_on?(voteable, options = {}) ⇒ Boolean
Checks if the current voter has voted on the voteable.
Instance Method Details
#current_vote_direction(voteable, options = {}) ⇒ Symbol?
Returns the current vote direction for a voter on a voteable
157 158 159 160 161 162 163 164 |
# File 'app/helpers/vote_fu/votes_helper.rb', line 157 def current_vote_direction(voteable, = {}) voter = .fetch(:voter) { default_voter } return nil unless voter scope = [:scope] vote = voteable.received_votes.find_by(voter: voter, scope: scope) vote&.direction end |
#downvote_button(voteable, options = {}) ⇒ Object
Renders a standalone downvote button
111 112 113 114 115 116 117 118 119 120 121 |
# File 'app/helpers/vote_fu/votes_helper.rb', line 111 def (voteable, = {}) voter = .fetch(:voter) { default_voter } render partial: "vote_fu/votes/downvote_button", locals: { voteable: voteable, voter: voter, scope: [:scope], label: .fetch(:label, "▼"), class: [:class] } end |
#like_button(voteable, options = {}) ⇒ Object
Renders a like button (upvote-only, social media style)
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/helpers/vote_fu/votes_helper.rb', line 75 def (voteable, = {}) voter = .fetch(:voter) { default_voter } render partial: "vote_fu/votes/like_button", locals: { voteable: voteable, voter: voter, scope: [:scope], liked_label: .fetch(:liked_label, "♥"), unliked_label: .fetch(:unliked_label, "♡"), show_count: .fetch(:show_count, true), class: [:class] } end |
#upvote_button(voteable, options = {}) ⇒ Object
Renders a standalone upvote button
94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/helpers/vote_fu/votes_helper.rb', line 94 def (voteable, = {}) voter = .fetch(:voter) { default_voter } render partial: "vote_fu/votes/upvote_button", locals: { voteable: voteable, voter: voter, scope: [:scope], label: .fetch(:label, "▲"), class: [:class] } end |
#vote_count(voteable, options = {}) ⇒ Object
Renders the vote count for a voteable
50 51 52 53 54 55 56 |
# File 'app/helpers/vote_fu/votes_helper.rb', line 50 def vote_count(voteable, = {}) render partial: "vote_fu/votes/count", locals: { voteable: voteable, scope: [:scope], format: .fetch(:format, :plusminus) } end |
#vote_dom_id(voteable, suffix = :widget, scope: nil) ⇒ String
Returns the DOM ID for a voteable's widget
130 131 132 133 |
# File 'app/helpers/vote_fu/votes_helper.rb', line 130 def vote_dom_id(voteable, suffix = :widget, scope: nil) scope_part = scope.present? ? "_#{scope}" : "" "vote_fu_#{voteable.model_name.singular}_#{voteable.id}#{scope_part}_#{suffix}" end |
#vote_widget(voteable, options = {}) ⇒ Object
Renders the full vote widget with upvote/downvote buttons and count
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/helpers/vote_fu/votes_helper.rb', line 24 def (voteable, = {}) voter = .fetch(:voter) { default_voter } render partial: "vote_fu/votes/widget", locals: { voteable: voteable, voter: voter, scope: [:scope], show_count: .fetch(:show_count, true), upvote_label: .fetch(:upvote_label, "▲"), downvote_label: .fetch(:downvote_label, "▼") } end |
#voted_on?(voteable, options = {}) ⇒ Boolean
Checks if the current voter has voted on the voteable
144 145 146 147 148 149 |
# File 'app/helpers/vote_fu/votes_helper.rb', line 144 def voted_on?(voteable, = {}) voter = .fetch(:voter) { default_voter } return false unless voter voteable.voted_by?(voter, direction: [:direction], scope: [:scope]) end |