Links outside rails application

I have a rails application I am developing and there’s basically a
minor thing I would like to do that makes my development a little bit
of a pain.
I’m currently doing my local development using ruby’s webrick. I’m
also relative new to web development, so pardon my ignorance, too.

Basically, my website has a menu system using CSS that is common to
all of its web pages, including the rails web pages. This is to allow
the user to jump from the rails “store” to any other part of the web-
site (home page, etc). Those external web pages are not inside the
rails directory.

Thus, all my pages have the menu embedded in them, like:

  <li class="top p1"><a href="index.html" class="top">Home</a></

li>

In rails, the views/layouts/*.rhtml pages have a similar menu embedded
in them.

What’s bothering me is that within rails those links cannot be
relative as they are in the rest of my website, as any relative path
takes me to localhost:3000/relative_path, instead of the root of my
website. The problem seems to happen both during development and
also deployment.

I was wondering if there was an easy way to keep the paths relative,
but make sure the web server knows they are relative to a certain root
directory and not the rails’ public root directory.

gga wrote:

rails directory.
relative as they are in the rest of my website, as any relative path
takes me to localhost:3000/relative_path, instead of the root of my
website. The problem seems to happen both during development and
also deployment.

I was wondering if there was an easy way to keep the paths relative,
but make sure the web server knows they are relative to a certain root
directory and not the rails’ public root directory.

If you are new to Web server configuration my suggestion is to just make
them absolute links. If you really really have to have them be relative
links for some reason you can use something like mod_rewrite with Apache
to have the Web server point the links to the proper places.


Michael W.

If you are new to Web server configuration my suggestion is to just make
them absolute links. If you really really have to have them be relative
links for some reason you can use something like mod_rewrite with Apache
to have the Web server point the links to the proper places.

Thanks, that’s what I’m doing now but I want to change that, as my
links will probably be updated often and I want to have something that
is as bullet-proof as possible.

mod_rewrite is probably not an option as my site is being hosted and
not under my full control.

I was wondering if rails’ routes.rb file could also be used for this
purpose. Ideally I would like to use a regexp to route any links
pointing to some subdirectory (subdomain).

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