Disable :.format routes in rails3

2020-05-17 02:55发布

Could you tell me how to disable the .:format options in rails routes? I only need html...

4条回答
爱情/是我丢掉的垃圾
2楼-- · 2020-05-17 03:10

You can wrap you routes around a scope (Rails 4):

scope format: false do
  # your routes here
end
查看更多
Juvenile、少年°
3楼-- · 2020-05-17 03:14

If you want pretty URLs and you don't like :format => false you might try this:

# :format must match the empty string
constraints :format => // do
  resources :monkeys
end

Even using with_options, the :format => false option is cumbersome, especially if you have a lot of routes.

查看更多
你好瞎i
4楼-- · 2020-05-17 03:28

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

This will constrain your routes to accept only html format:

constraints :format => "html" do
  resources :posts do
    resources :comments
  end
end

However, it won't remove (.:format) part from your rake routes output.

查看更多
Evening l夕情丶
5楼-- · 2020-05-17 03:33

In 3.1.1 at least you can add , :format => false to the end of the route.

Found here: http://guides.rubyonrails.org/routing.html#request-based-constraints under section 3.11 Route Globbing

eg..

match '*pages' => 'pages#show', :format => false

Which would allow params[:pages] to include a period.

查看更多
登录 后发表回答