Skip to content

Instantly share code, notes, and snippets.

@dlederle
Last active December 6, 2021 20:39
Show Gist options
  • Save dlederle/81d08acf23f798be58525f51603b9fe1 to your computer and use it in GitHub Desktop.
Save dlederle/81d08acf23f798be58525f51603b9fe1 to your computer and use it in GitHub Desktop.
hotwire clicker (`rails g resource Click count:integer`)
Current count: <%= @click.count %>
class ClicksController < ApplicationController
def show
@click = Click.find(params[:id])
end
def update
@click = Click.find(params[:id])
@click.update(count: @click.count + 1)
respond_to do |format|
format.turbo_stream do
render turbo_stream: turbo_stream.update("click-count", partial: "clicks/count")
end
end
end
end
<turbo-frame id="click-count">
<%= render "count" %>
</turbo-frame>
<br />
<%= link_to "+", @click, method: :patch %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment