禁用:rails3中的.format路由

Bvu*_*Ic7 31 formatting routing ruby-on-rails ruby-on-rails-3

你能告诉我如何在rails路由中禁用.:format选项吗?我只需要HTML ...

Jim*_*ris 50

在3.1.1中,至少可以添加:format => false到路径的末尾.

在此处找到:http: //guides.rubyonrails.org/routing.html#request-based-constraints in 3.11 Route Globbing

例如..

match '*pages' => 'pages#show', :format => false
Run Code Online (Sandbox Code Playgroud)

这将允许参数[:pages]包含一个句点.


Hei*_*kki 16

http://guides.rubyonrails.org/routing.html#request-based-constraints

这将限制您的路由只接受html格式:

constraints :format => "html" do
  resources :posts do
    resources :comments
  end
end
Run Code Online (Sandbox Code Playgroud)

但是,它不会(.:format)rake routes输出中删除部分.


Dun*_*son 11

您可以在范围内包装路径(Rails 4):

scope format: false do
  # your routes here
end
Run Code Online (Sandbox Code Playgroud)