From eefb439580f875017aa32336110957697c37c7f0 Mon Sep 17 00:00:00 2001 From: Andy Waite Date: Wed, 22 Feb 2023 11:57:03 -0500 Subject: [PATCH 1/2] Support `current` in URL Closes https://github.com/rubyapi/rubyapi/issues/1215 --- app/controllers/application_controller.rb | 5 +++++ config/routes.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index eb4af72d7..a46759fa4 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,6 +5,11 @@ class ApplicationController < ActionController::Base after_action :set_feature_headers def set_ruby_version + if params[:version] == "current" + redirect_to request.path.sub(%r{^/current}, "/#{RubyConfig.default_ruby_version.version}") + return + end + version = RubyConfig.version_for(params[:version]) || RubyConfig.default_ruby_version Current.ruby_version = version diff --git a/config/routes.rb b/config/routes.rb index afc5260bc..57b5d5db4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,7 +8,7 @@ ruby_versions = RubyConfig.ruby_versions.collect { |v| Regexp.escape(v.version) } - scope "(:version)", constraints: { version: /#{ruby_versions.join("|")}/ } do + scope "(:version)", constraints: { version: /#{ruby_versions.join("|")}|current/ } do root to: "home#index", as: :versioned_root post '/set_theme', to: 'home#set_theme' # We need the search path to be prefixed with `o/` so that the RDOc links will From 4d4829a47b13ef64ca726b7479fbc9b93379fcb0 Mon Sep 17 00:00:00 2001 From: Andy Waite Date: Sat, 25 Feb 2023 20:43:49 -0500 Subject: [PATCH 2/2] PR feedback --- app/controllers/application_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a46759fa4..3e5477140 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -6,7 +6,8 @@ class ApplicationController < ActionController::Base def set_ruby_version if params[:version] == "current" - redirect_to request.path.sub(%r{^/current}, "/#{RubyConfig.default_ruby_version.version}") + permitted_params = params.permit(:object, :engine, :q, :page, :theme) + redirect_to permitted_params.merge(version: RubyConfig.default_ruby_version.version) return end