Last active
December 6, 2021 20:39
-
-
Save dlederle/81d08acf23f798be58525f51603b9fe1 to your computer and use it in GitHub Desktop.
hotwire clicker (`rails g resource Click count:integer`)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Current count: <%= @click.count %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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