I have a rails app where a route is defined as
get "/:username", to: "profiles#show", as: :show_profile, constraints: UsernameConstraints.new
And UsernameConstraints
is defined as
class UsernameConstraints
#Some code
def matches?(request)
request.path.match?(/.*/)
end
#Some code
end
So that usernames can be something like myapp.com/user.name
How do I change this code to accept usernames with two or more dots (myapp.com/something.like.this
)?
At the moment I can't get rid of the No route matches
error.
I tried adding format: true
to the route and re-building the username in the controller using the parameters:
myapp.com/something.like.this
{"username"=>"something", "format"=>"like.this"}
params[:username] = "#{params[:username]}.#{params[:format]}"
But it’s not a clean solution and also the route does not match any more simple usernames like /username
question from:
https://stackoverflow.com/questions/65877179/rails-two-or-more-dots-in-the-url 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…