Files
nairobi/app/helpers/application_helper.rb
2015-09-15 14:11:12 +02:00

38 lines
1.0 KiB
Ruby

module ApplicationHelper
def votes_percentage(vote, debate)
return "0%" if debate.total_votes == 0
if vote == 'likes'
debate.likes.percent_of(debate.total_votes).to_s + "%"
elsif vote == 'dislikes'
(100 - debate.likes.percent_of(debate.total_votes)).to_s + "%"
end
end
def home_page?
return false if user_signed_in?
# Using path because fullpath yields false negatives since it contains
# parameters too
request.path == '/'
end
def transparency_page?
request.path == '/transparency'
end
def opendata_page?
request.path == '/opendata'
end
def header_css
home_page? || transparency_page? || opendata_page? ? '' : 'results'
end
# if current path is /debates current_path_with_query_params(foo: 'bar') returns /debates?foo=bar
# notice: if query_params have a param which also exist in current path, it "overrides" (query_params is merged last)
def current_path_with_query_params(query_parameters)
url_for(request.query_parameters.merge(query_parameters))
end
end