David Kimura PRO
Joined 7/18/2015
Drifting Ruby Owner
Ruby Rogues Panelist
David Kimura PRO said over 3 years ago on Gathering Questionnaire Responses :
Just some thoughts on weights... For the weights, I would recommend not trying to match 100%. It's not too difficult, but it's really annoying. So much front end validation to do and requiring the user to do some math to match up values to 100%. Instead, if you have 10 questions and you give them a weight of 50 each, then each question would be 10% of the total score. This will be much easier logic to handle. You could use a stimulus controller to add up each of the weight inputs and show a percentage value as you setup the questionnaire. 

David Kimura PRO said over 3 years ago on StimulusJS, Active Storage and DropzoneJS :
  Can you post the relevant bits of the stimulus controller, any console errors in the browser? Typically, it would error out in the assets compilation if there is a missing asset or something that you're referencing.

David Kimura PRO said over 3 years ago on StimulusJS, Active Storage and DropzoneJS :
   This is a CORS issue likely due to the JS doing a “direct upload”. In order to fix this, you will need to change the digital ocean spaces CORS settings. You would likely have this same problem if you were using active storage direct uploads without drop zone.

David Kimura PRO said over 3 years ago on Nested Comments from Scratch :
  It looks like your instance variable commentable got set to a Comment instance instead of an Item. Do you have the app set up for a comment to receive a comment? And when you set the commentable, you should likely be passing in the Item instead of the Comment.

David Kimura PRO said over 3 years ago on Diving into Hotwire :
  Have a look at the source https://github.com/hotwired/turbo-rails/blob/main/app/models/concerns/turbo/broadcastable.rb on the broadcast methods. At the top, there is a bit where they show a callback to then trigger a broadcast.

after_create_commit :broadcast_later

private

def broadcast_later
  broadcast_prepend_later_to examiner.identity, :clearances
end

Since you will want to update a count, you would likely want to replace instead of prepend. The broadcast_replace_to would likely be what you would want. However, if there are a lot of users, you may want to do this in a background job with broadcast_replace_later_to instead. It looks like this allows you to specify a partial as well as the local variables which in your case would be the product count..

# Replace this broadcastable model in the dom for subscribers of the stream name identified by the passed
# <tt>streamables</tt>. The rendering parameters can be set by appending named arguments to the call. Examples:
#
#   # Sends <turbo-stream action="replace" target="clearance_5"><template><div id="clearance_5">My Clearance</div></template></turbo-stream>
#   # to the stream named "identity:2:clearances"
#   clearance.broadcast_replace_to examiner.identity, :clearances
#
#   # Sends <turbo-stream action="replace" target="clearance_5"><template><div id="clearance_5">Other partial</div></template></turbo-stream>
#   # to the stream named "identity:2:clearances"
#   clearance.broadcast_replace_to examiner.identity, :clearances, partial: "clearances/other_partial", locals: { a: 1 }
def broadcast_replace_to(*streamables, **rendering)
  Turbo::StreamsChannel.broadcast_replace_to *streamables, target: self, **broadcast_rendering_with_defaults(rendering)
end