0

I'm currently working on something that would interpret part of the request url as a relative path (yes, I'm aware that this could pose a security risk).

It would look something like

/page/path/to/something

The parameter part would be /path/to/something.

Can I do this with regular routing or do I have to use something like rails metal to handle this myself?

2 Answers 2

1

Use a routing constraint to allow slashes in route segments; nutshell (roughly):

match "page/:fqp" => "what#ever", :constraints => { :fqp => /[a-zA-Z0-9\/]*/ }
Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for pointing me in the right direction, however, there also is route globbing, I'll post an answer to detail that.
@Femaref Yes, there is, but IMO constraints are cleaner and more predictable, so I didn't include that.
I'll accept your answer as I agree with you on the general case.
@Femaref The funny part is that I used to think otherwise, not too long ago. Ultimately it just depends--for filenames, constraints are a better option, IMO.
In the end it will be past through grit and a hash will be generated, based on that the actual file will be accessed. So it doesn't really matter in this case.
|
0

In addition to Deve Newton's answer, there also is route globbing, of the form

get "/page/*path", => "page#show"

It matches the page part and puts any additional content in the path as params[:path] in the detailed controller action.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.