开发者

How can i visit urls with .html suffix

My rails version is 2.3.5(2.3+)

How can I visit urls with .html suffix? Just like localhost:3000/welcome.html (welcome is a controller).

I got routing errors when I vi开发者_如何学运维sit urls above.But it works if the url with format param like this:

localhost:3000/welcome?format=html

In routes.rb:

ActionController::Routing::Routes.draw do |map|
  map.root :controller => "welcome"
  map.resources :users
  map.resource :session

  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'
end

But but but I found localhost:3000/users.html works.


Use this route to connect to an controller:

map.connect "welcome.html", :controller => :welcome, :action => :index

Whether there is .html does not matter for routing purposes, it is just like any other path connecting to any other controller. So no need to modify your controller for this.
Using the format=html results in a parameter, so a controller can return the specific type of result, which is not what you want according to your question.

According to your information this (allowing .html in your paths) is automatically implemented when creating routes with the map.resources method. Since it is working for users in your example.


You could try this:

map.connect ':controller.:format', :action => :index
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜