Files
nairobi/app/components/polls/questions/answers_component.html.erb
Javi Martín f384451d9f Always generate <button> tags with button_to
In Rails 6.1 and earlier, `button_to` generated a <button> tag when it
received the content as a block, but an <input> tag when receiving
the content as the first parameter.

That's why we were using blocks with `button_to` most of the time; for
starters, <button> tags accept pseudocontent and so are easier to style.

In Rails 7.0, `button_to` always generates a <button> tag [1], so we're
simplifying the code what uses `button_to`, passing the content as a
first parameter instead of passing it as a block.

[1] https://guides.rubyonrails.org/v7.1/configuring.html#config-action-view-button-to-generates-button-tag
2024-04-15 15:39:28 +02:00

36 lines
1.7 KiB
Plaintext

<div class="poll-question-answers">
<% if can?(:answer, question) && !question.poll.voted_in_booth?(current_user) %>
<% question_answers.each do |question_answer| %>
<% if already_answered?(question_answer) %>
<%= button_to question_answer.title,
question_answer_path(question, user_answer(question_answer)),
method: :delete,
remote: true,
title: t("poll_questions.show.voted", answer: question_answer.title),
class: "button answered",
"aria-pressed": true %>
<% else %>
<%= button_to question_answer.title,
answer_question_path(question, answer: question_answer.title),
remote: true,
title: t("poll_questions.show.vote_answer", answer: question_answer.title),
class: "button secondary hollow",
"aria-pressed": false,
disabled: disable_answer?(question_answer) %>
<% end %>
<% end %>
<% elsif !user_signed_in? %>
<% question_answers.each do |question_answer| %>
<%= link_to question_answer.title, new_user_session_path, class: "button secondary hollow" %>
<% end %>
<% elsif !current_user.level_two_or_three_verified? %>
<% question_answers.each do |question_answer| %>
<%= link_to question_answer.title, verification_path, class: "button secondary hollow" %>
<% end %>
<% else %>
<% question_answers.each do |question_answer| %>
<span class="button secondary hollow disabled"><%= question_answer.title %></span>
<% end %>
<% end %>
</div>