today_ai_weather/app/views/votes/_vote_buttons.html.erb
songtianlun e5c1461e8a feat: add voting functionality for votable entities
- Create VotesController to manage voting actions
- Implement Vote model with polymorphic associations
- Add vote buttons to the city and weather art views
- Integrate vote counting and user vote tracking
- Define routes for the votes resource

This commit sets up a voting mechanism for cities and weather arts, allowing users to upvote or downvote. It includes seamless integration of user sessions to track individual votes, ensuring votes can be modified or deleted based on user interaction.
2025-02-07 13:10:53 +08:00

30 lines
1.1 KiB
Plaintext

# app/views/votes/_vote_buttons.html.erb
<%
Rails.logger.debug "Votable object: #{votable.inspect}"
Rails.logger.debug "Votable class: #{votable.class}"
Rails.logger.debug "Votable present?: #{votable.present?}"
%>
<div id="<%= "#{votable.class.name.downcase}_votes_#{votable.id}" %>">
<div class="flex items-center space-x-2">
<%= button_to votes_path,
params: {
"#{votable.class.name.downcase}_id": votable.id,
vote_type: :upvote
},
method: :post,
class: "btn btn-sm #{votable.user_vote(session.id) == 'upvote' ? 'btn-primary' : ''}" do %>
👍 <%= votable.vote_counts[:upvotes] %>
<% end %>
<%= button_to votes_path,
params: {
"#{votable.class.name.downcase}_id": votable.id,
vote_type: :downvote
},
method: :post,
class: "btn btn-sm #{votable.user_vote(session.id) == 'downvote' ? 'btn-error' : ''}" do %>
👎 <%= votable.vote_counts[:downvotes] %>
<% end %>
</div>
</div>