Tim Pease
2/18/2008 11:53:00 PM
On Feb 17, 2008, at 2:41 PM, Leslie Viljoen wrote:
> On Feb 15, 2008 6:18 PM, Tim Pease <tim.pease@gmail.com> wrote:
>>
>>> 2. How do you create links to other content pages without specifying
>>> the URL directly?
>>
>> <%= link_to_page( :title => "Your Page Title" ) %>
>
> Because the "url_for" function produces url's that start with a "/",
> I cannot open my generated index.html as a file on my harddrive -
> all the links are absolute. I changed the url_for function to leave
> out the leading slash and now everything seems to work locally
> and through a server. Can you think of a problem this may cause?
I can't think of a problem that it will cause, but I also can't think
of a problem it will solve, either. Your fix will work for pages
located at the root of the website. But for pages that are nested in
some directory structure, they will not have access to the CSS files
or other resources. The reason for this is that the layout contains
the HTML head tag, and that will be the same for all the pages. When
it is configured to work for one directory level, it will not work for
any other directory levels.
Webby has a "basepath" filter that allows you to rewrite the base path
for any URL in the system. I use this filter for websites that are not
hosted at the root of the web server. This filter looks at all the
URLs in a page and replaces that leading slash "/" character with the
new base path.
In your situation, you could rewrite the base URL to "."
rake rebuild BASE="."
That will work for viewing pages directly from the disk. However, you
will run into the problem where pages nested in some directory won't
be able to load the CSS files, etc.
Blessings,
TwP