Skip to content

Instantly share code, notes, and snippets.

@pama
Last active March 31, 2022 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pama/10ff1e508994e81ea13472017ffc8615 to your computer and use it in GitHub Desktop.
Save pama/10ff1e508994e81ea13472017ffc8615 to your computer and use it in GitHub Desktop.
<%= turbo_stream.update "panel" do %>
<% if params[:position].to_i <= 5 %>
<p>Less or equal to 5</p>
<% else %>
<p>more than 5</p>
<% end %>
<% end %>
import { Controller } from "@hotwired/stimulus"
import { get } from "@rails/request.js"
export default class extends Controller {
greet(event) {
let value = event.currentTarget.value
get(`/home/greet?position=${value}`, {
responseKind: "turbo-stream"
})
}
}
class HomeController < ApplicationController
def index
end
def greet
respond_to do |format|
format.turbo_stream
end
end
end
<div data-controller="hello">
<input type="range"
name="custom_range"
id="custom_range"
value="6"
min="0"
max="10"
step="0.5" data-action="change->hello#greet">
<div id="panel"></div>
</div>
Rails.application.routes.draw do
get 'home/index'
get 'home/greet'
root "home#index"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment