dev
Joined 6/19/2021
dev said over 3 years ago on Sign in with Apple :
fixed. I missed `  skip_before_action :verify_authenticity_token` in my controller

dev said over 3 years ago on Slim Select with Stimulus :
Thanks for the episode, David!
As a bonus, how would you implement the "addable" function into our Rails app (create tag if doesn't exist yet)?

dev said almost 3 years ago on Real-time Comments and Voting :
Why re-render the entire comment template? The code can be simplified
Partial comment
#app/views/comments/_comment.html.erb
<%= content_tag :div, id: dom_id(comment), class: "card mb-3" do %>
  <div class="card-body">
    <h5 class="card-title"><%= comment.user.email %> said:</h5>
    <p class="card-text"><%= comment.content %></p>
    <p id='<%= dom_id(comment)%>_count'>
      <%= comment.vote_count %>
    </p>
    <%= link_to "Up Vote", comment_votes_path(comment, choice: :up_vote, format: :turbo_stream), class: "card-link" %>
    <%= link_to "Down Vote", comment_votes_path(comment, choice: :down_vote, format: :turbo_stream), class: "card-link" %>
  </div>
<% end %>
model Vote
# app/models/vote.rb
after_update_commit do
  broadcast_update_to("comments", target: "#{dom_id(comment)}_count", html: comment.vote_count)
end


dev said almost 3 years ago on Real-time Comments and Voting :
  gonzalezarthur Why does the model name Tueet (class Tueet < ApplicationRecord) have the file name tweet.rb (# models/tweet.rb)?

Some refactoring
class VotesController < ApplicationController
  ...
  def show
    @comment = Comment.find(params[:comment_id])
    @vote = Vote.find_or_create_by(user: current_user, comment: @comment)

    @vote.voted(params[:choice])
  end

class Vote < ApplicationRecord
  ...
  def voted(choice)
    return unless choice.in?(Vote::choices.keys)

    case choice
    when 'up_vote'
      up_vote? ? cancel! : up_vote!
    when 'down_vote'
      down_vote? ? cancel! : down_vote!
    end
  end




dev said almost 3 years ago on Real-time Comments and Voting :
My project, which is based on the source code from this video. 

Fixed

  • bugs in the Votes model (has_many :votes, dependent: :destroy move to User model ).

Added new feature:

  • The title of the vote button changes depending on user actions: up_vote(down_vote) -> undo_vote -> up_vote(down_vote). Title change usually only for current users (Stimulus controller);
  • Unauthenticated users cannot vote on a comment (Stimulus controller );
  • The user who voted will receive a flash message with information;
  • Added the ability for the author of a comment to delete it (Stimulus controller);
  • Hotwire flash messages (lTailwind style);
  • Autohide and manual closing of Hotwire flash messages (Bootstrap JS and Stimulus controller);
  • Comments counter that changes dynamically after adding/removing objects (broadcasts html).
  • Counter votes, rewritten only on broadcasts HTML parts;
  • Small refactoring code