Could you tell me how to disable the .:format options in rails routes? I only need html...
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.
回答2:
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.
回答3:
You can wrap you routes around a scope (Rails 4):
scope format: false do
# your routes here
end
回答4:
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.