This is a robust approach to making controller/{conference_name}/* case insensitive. Richard reported this issue in regards to West2026 flyer.
This commit is contained in:
parent
dc9665b79d
commit
69e8a29fc7
@ -9,7 +9,7 @@ class AdministrationController < ApplicationController
|
|||||||
|
|
||||||
def edit
|
def edit
|
||||||
return do_404 unless logged_in? && current_user.administrator?
|
return do_404 unless logged_in? && current_user.administrator?
|
||||||
@this_conference = Conference.find_by!(slug: params[:slug])
|
@this_conference = Conference.find_by!("LOWER(slug) = LOWER(?)", params[:slug])
|
||||||
@page_title = 'articles.conferences.headings.edit'
|
@page_title = 'articles.conferences.headings.edit'
|
||||||
@main_title_vars = { vars: { title: @this_conference.title } }
|
@main_title_vars = { vars: { title: @this_conference.title } }
|
||||||
render 'new'
|
render 'new'
|
||||||
|
|||||||
@ -123,7 +123,7 @@ class ApplicationController < BaseController
|
|||||||
@page_title ||= 'page_titles.403.Please_Check_Email'
|
@page_title ||= 'page_titles.403.Please_Check_Email'
|
||||||
|
|
||||||
if (request.present? && request.referrer.present? && conference = /^\/conferences\/(\w+)\/register\/?$/.match(request.referrer.gsub(/^https?:\/\/.*?\//, '/')))
|
if (request.present? && request.referrer.present? && conference = /^\/conferences\/(\w+)\/register\/?$/.match(request.referrer.gsub(/^https?:\/\/.*?\//, '/')))
|
||||||
@this_conference = Conference.find_by!(slug: conference[1])
|
@this_conference = Conference.find_by!("LOWER(slug) = LOWER(?)", conference[1])
|
||||||
@banner_image = @this_conference.cover_url
|
@banner_image = @this_conference.cover_url
|
||||||
template = 'conferences/email_confirm'
|
template = 'conferences/email_confirm'
|
||||||
end
|
end
|
||||||
@ -283,7 +283,7 @@ class ApplicationController < BaseController
|
|||||||
@page_title ||= 'page_titles.403.Please_Check_Email'
|
@page_title ||= 'page_titles.403.Please_Check_Email'
|
||||||
|
|
||||||
if (request.present? && request.referrer.present? && conference = /^\/conferences\/(\w+)\/register\/?$/.match(request.referrer.gsub(/^https?:\/\/.*?\//, '/')))
|
if (request.present? && request.referrer.present? && conference = /^\/conferences\/(\w+)\/register\/?$/.match(request.referrer.gsub(/^https?:\/\/.*?\//, '/')))
|
||||||
@this_conference = Conference.find_by!(slug: conference[1])
|
@this_conference = Conference.find_by!("LOWER(slug) = LOWER(?)", conference[1])
|
||||||
@banner_image = @this_conference.cover_url
|
@banner_image = @this_conference.cover_url
|
||||||
template = 'conferences/email_confirm'
|
template = 'conferences/email_confirm'
|
||||||
end
|
end
|
||||||
@ -617,7 +617,7 @@ class ApplicationController < BaseController
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
def set_conference
|
def set_conference
|
||||||
@this_conference = Conference.find_by!(slug: params[:slug])
|
@this_conference = Conference.find_by!("LOWER(slug) = LOWER(?)", params[:slug])
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_conference_registration
|
def set_conference_registration
|
||||||
|
|||||||
@ -76,7 +76,7 @@ class ConferenceAdministrationController < ApplicationController
|
|||||||
|
|
||||||
def previous_stats
|
def previous_stats
|
||||||
set_conference
|
set_conference
|
||||||
conference = Conference.find_by_slug(params[:conference_slug])
|
conference = Conference.find_by("LOWER(slug) = LOWER(?)", params[:conference_slug])
|
||||||
return do_403 unless conference.is_public
|
return do_403 unless conference.is_public
|
||||||
get_stats(false, nil, conference)
|
get_stats(false, nil, conference)
|
||||||
logger.info "Generating #{conference.slug}.xls"
|
logger.info "Generating #{conference.slug}.xls"
|
||||||
|
|||||||
6
config/initializers/slug_constraint.rb
Normal file
6
config/initializers/slug_constraint.rb
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
class SlugConstraint
|
||||||
|
def matches?(request)
|
||||||
|
request.params[:slug] = request.params[:slug].downcase if request.params[:slug]
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -3,6 +3,10 @@ Sidekiq::Web.set :sessions, false
|
|||||||
|
|
||||||
BikeBike::Application.routes.draw do
|
BikeBike::Application.routes.draw do
|
||||||
|
|
||||||
|
# Redirect uppercase CONFERENCES to lowercase conferences
|
||||||
|
get '/CONFERENCES(*anything)', to: redirect { |params, request| "/conferences#{params[:anything]}" }
|
||||||
|
get '/CONFERENCES', to: redirect('/conferences')
|
||||||
|
|
||||||
# Conferences
|
# Conferences
|
||||||
scope :conferences do
|
scope :conferences do
|
||||||
root 'conferences#list', as: :conferences
|
root 'conferences#list', as: :conferences
|
||||||
@ -10,7 +14,7 @@ BikeBike::Application.routes.draw do
|
|||||||
get 'new' => 'administration#new', as: :new_conference
|
get 'new' => 'administration#new', as: :new_conference
|
||||||
post 'save' => 'administration#save', as: :save_conference
|
post 'save' => 'administration#save', as: :save_conference
|
||||||
|
|
||||||
scope ':slug', constraints: { slug: /[^\/]+/ } do
|
scope ':slug', constraints: SlugConstraint.new do
|
||||||
root 'conferences#view', as: :conference
|
root 'conferences#view', as: :conference
|
||||||
|
|
||||||
get 'edit' => 'administration#edit', as: :edit_conference
|
get 'edit' => 'administration#edit', as: :edit_conference
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user