Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.1 force .html instead of no extension

One of my clients wants his new Rails application to look more like his traditional web site. He wants to know if I can force urls to have a file extension, preferably .html.

I don't want to hard-code the extension in routes.rb as

match ':controller/:action/:id.html'

(or similar) because the client also wants to have a respond_to-style JSON API which requires the use of .:format.

Can this be done?

like image 462
Moshe Katz Avatar asked Feb 23 '23 05:02

Moshe Katz


2 Answers

Just as Mattias Wadman suggested, in config/application.rb add:

AppName::Application.default_url_options = { :format => "html" }

But also change config/routes.rb to:

root :to => 'pages#home', :defaults => { :format => "html" }
like image 86
Eden Townsend Avatar answered Feb 24 '23 18:02

Eden Townsend


Im no Rails routing expert but I tried to force HTML format by changing the default URL options and at least the URL helpers seams to generate .html URLs now, it's a start.

config/application.rb (at the bottom)

AppName::Application.default_url_options = {:format => "html"}
like image 38
Mattias Wadman Avatar answered Feb 24 '23 18:02

Mattias Wadman