Forum: Ruby on Rails Add .html extension by default

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
gerold (Guest)
on 2009-02-24 13:17
(Received via mailing list)
Hi all,

i would like to add the .html extension by default to all my
resources. What is the best way to do that? The reason for this is
that i need to download the generated sites via wget and i need
the .html extension for the downloaded files. Also it would be nice if
the link_to would automatically generate the links with .html...

Thanks,

Gerold
MaD (Guest)
on 2009-02-24 13:29
(Received via mailing list)
how about a before/after_save callback? i guess that would work.
gerold (Guest)
on 2009-02-24 14:00
(Received via mailing list)
Maybe i was a little too unspecific with my description. Let me try
again:

The website has multiple nested pages and i can address them with
e.g. /pages/first /pages/first/subpage
Now when i want to wget all of the pages the downloaded files are
called first and subpage but
i'd like them to be called first.html and subpage.html so i figured
the easiest way to do that is to just add
.html at the end of all pages by default.

So when i add a resource to routes.rb like

resources :pages

i can call /pages/1 and i get the first page but again if i download
it the file would be called 1 instead of 1.html...
Also if i use link_to or url_for i get the links generated without
the .html at the end...

i tried

resources :pages, :format => :html

but i think the problem here is that html is the default mimetype and
so it's ignored. One sollution could be to set
another mimetype as default so i would have to add the html format for
every link i generate which would be ok for me...
MaD (Guest)
on 2009-02-24 14:31
(Received via mailing list)
sounds a little bit silly, bit i just tried a route like
  map.connect ':controller/:action.html'
that is actually working for me
  http://localhost:3000/bla/index.html
gerold (Guest)
on 2009-02-24 14:40
(Received via mailing list)
i also figured that but i would really like to use resources...
Rimantas L. (Guest)
on 2009-02-24 14:49
(Received via mailing list)
> i would like to add the .html extension by default to all my
> resources. What is the best way to do that? The reason for this is
> that i need to download the generated sites via wget and i need
> the .html extension for the downloaded files. Also it would be nice if
> the link_to would automatically generate the links with .html...

That's a very bad idea. The better idea might be to add -E option to
your
wget call (and maybe -k too).


Regards,
Rimantas
--
http://rimantas.com/
gerold (Guest)
on 2009-02-24 15:12
(Received via mailing list)
why is it a "very bad" idea? i don't think that would be harmfull in
any way. But if i can't find an easy way to do it i will have to fix
it with wget...
Rimantas L. (Guest)
on 2009-02-24 16:15
(Received via mailing list)
> why is it a "very bad" idea? i don't think that would be harmfull in
> any way. But if i can't find an easy way to do it i will have to fix
> it with wget...

Well, sorry, but hacking application to get the result for the
_external_ application (the same result you can get by adding two
characters to the command line)
does not sound like a good idea to me.

There are other reasons why file extensions are bad on the
web in general and in REST case in particular, but I won't go into
that now.

Regards,
Rimantas
--
http://rimantas.com/
This topic is locked and can not be replied to.