Easy way to add .html extension to all URLs?

Is there an easy way to add a .html extension to the end of all URLs?

I’ve tried adding this to routes.rb:
map.connect ‘:controller/:action/:id.html’, :format => ‘html’

or this to the ApplicationController:
def default_url_options(options)
{ :format => ‘html’ }
end

but neither of these methods renders the right link with the link_to
tag <%= link_to ‘Show’, post] %>

Do I have to use or is there a
more elegant solution?

Thanks!

et wrote:

Is there an easy way to add a .html extension to the end of all URLs?

I’ve tried adding this to routes.rb:
map.connect ‘:controller/:action/:id.html’, :format => ‘html’

but neither of these methods renders the right link with the link_to
tag <%= link_to ‘Show’, post] %>

Thanks!

Where did you put that extra route?

Routes are matched in the order they feature in your routes.rb file

so,

map.admin ‘admin/:action/:id.html’, :controller => ‘admin’, :format =>
“html”

map.connect ‘:controller/:action/:id.html’, :format => “html”
map.connect ‘:controller/:action.html’, :format => “html”

now the defaults

map.connect ‘:controller/:action/:id.:format’
map.connect ':controller/:action/:id

should generate with .html for you,
but why do you want this?

by all means provide a legacy fallback to .html,
but moving forward,
why is it good to depend on this extension?

I have the extra route above the default ones, but is there a way to
generate “/posts/1.html” using <%= link_to ‘Show’, post %> or a
simpler method than what I have above?

Right now /posts/1.html works if I navigate directly to it, but the
links on the views/posts/index.html.erb are still rendering as /posts/
1

The reason I want the extension is to make sure search engines will
see /posts/1.html as a document in the first level directory as
opposed to /posts/1 as a second deeper level directory.

On Jul 14, 4:52 am, Matthew R. Jacobs <rails-mailing-l…@andreas-