diff --git a/.ruby-version b/.ruby-version index ff365e0..0aec50e 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.1.3 +3.1.4 diff --git a/Gemfile b/Gemfile index a434d08..6c29320 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby "3.1.3" +ruby "3.1.4" # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" gem "rails", "~> 7.0.4", ">= 7.0.4.3" @@ -19,7 +19,7 @@ gem "puma", "~> 5.0" gem "importmap-rails" # Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] -gem "turbo-rails" +gem "turbo-rails", "= 2.0.0.pre.beta.2" # Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev] gem "stimulus-rails" diff --git a/Gemfile.lock b/Gemfile.lock index b3c8d0c..36df48b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -192,7 +192,7 @@ GEM stringio (3.1.0) thor (1.3.0) timeout (0.4.1) - turbo-rails (1.5.0) + turbo-rails (2.0.0.pre.beta.2) actionpack (>= 6.0.0) activejob (>= 6.0.0) railties (>= 6.0.0) @@ -217,6 +217,7 @@ GEM PLATFORMS arm64-darwin-22 + arm64-darwin-23 DEPENDENCIES bootsnap @@ -231,13 +232,13 @@ DEPENDENCIES sprockets-rails sqlite3 (~> 1.4) stimulus-rails - turbo-rails + turbo-rails (= 2.0.0.pre.beta.2) tzinfo-data web-console webdrivers RUBY VERSION - ruby 3.1.3p185 + ruby 3.1.4p223 BUNDLED WITH 2.4.3 diff --git a/app/controllers/test_controller.rb b/app/controllers/test_controller.rb new file mode 100644 index 0000000..48edcd0 --- /dev/null +++ b/app/controllers/test_controller.rb @@ -0,0 +1,15 @@ +class TestController < ApplicationController + def index + @test = session[:test].presence&.to_i || 1 + numbers = [@test] + numbers += 5.times.map { |i| @test + i + 1 } + numbers += 5.times.map { |i| @test - i - 1 } + + @available_options = numbers.sort.map { |i| ["Option #{i}", i] } + end + + def create + session[:test] = params[:test] + redirect_to action: :index + end +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index df09a99..a794192 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -8,6 +8,10 @@ <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> <%= javascript_importmap_tags %> + + <%= turbo_refreshes_with method: :morph, scroll: :preserve %> + + <%= yield :head %>
diff --git a/app/views/test/index.html.erb b/app/views/test/index.html.erb new file mode 100644 index 0000000..790d6e3 --- /dev/null +++ b/app/views/test/index.html.erb @@ -0,0 +1,8 @@ +Selected Option: <%= @test %>
+ +<%= form_tag test_path do %> + <%= select_tag :test, + options_for_select(@available_options, @test), + onchange: "this.form.requestSubmit()" + %> +<% end %> diff --git a/config/routes.rb b/config/routes.rb index 262ffd5..a29d81c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,4 +3,7 @@ # Defines the root path route ("/") # root "articles#index" + post :test, to: "test#create" + + root "test#index" end