How do URL's like /images/xx get mapped to the correct place

In the default routing file there is nothing about the /images/ URL, or
the /javascript/ urls.

…So where is the code which makes these special URLs work?

Cheers

Ed W

There is no code needed to make these work, as all requests look in the
public folder first. If nothing is found (404), then the request goes
through Rails.

Brian H. wrote:

If nothing is found (404), then the request goes through Rails.

Actually that kind of depends upon how your Web server is configured.
You’re quite right that there’s nothing particularly special about the
URLs, though.

…So where is the code which makes these special URLs work?

Some people configure their Web server so that the Rails application’s
“public” folder is the document root for the Web; then “/images/…”
works just like any conventional URL, fetching a file from that document
root. In such a case it often makes sense, if the Web server supports
it, to have a “not found” document set up that’s actually one of the
Rails dispatch.xyz files. Then things work exactly as Brian said.

Other people put their Rails application somewhere outside the document
root for the Web server, often for security reasons. It’s common to
create a symbolic link in the Web server part of the filesystem to the
Rails ‘public’ directory in such a case. The use of a “not found”
handler to run the Rails dispatcher may still apply; or in some cases,
using URL rewriting to get the dispatcher to execute can be useful.
Rails applications’ config/routes.rb files help reduce or eliminate the
need for URL rewriting once the application is running, but they don’t
eliminate the need for it (sometimes) to get the dispatcher kicked off
in the first place, be it FastCGI or ‘slow’ CGI.

A more complex case occurs when you want a Rails application to exist
away from the document root, in a subdirectory. Perhaps you want more
than one Rails application running at once in one single domain - you’re
unable or unwilling to put each one under a virtual domain. In this case
the connections between Rails URLs, image URLs etc. and physical file
locations can get quite abstract but funamdentally the same basic
approaches of symbolic linking, Not Found handlers or rewriting seem to
underpin the majority of installations.

Hi

Actually that kind of depends upon how your Web server is configured.
You’re quite right that there’s nothing particularly special about the
URLs, though.

Aha, I see. That makes more sense now.

Cheers

Ed W

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs