Ruby on rails 禁用:。格式化rails3中的路由
您能告诉我如何禁用rails路由中的。:格式选项吗?我只需要html… 这将限制您的路由仅接受html格式:Ruby on rails 禁用:。格式化rails3中的路由,ruby-on-rails,routing,formatting,ruby-on-rails-3,Ruby On Rails,Routing,Formatting,Ruby On Rails 3,您能告诉我如何禁用rails路由中的。:格式选项吗?我只需要html… 这将限制您的路由仅接受html格式: constraints :format => "html" do resources :posts do resources :comments end end 但是,它不会从rake routes输出中删除(:format)部分。在3.1.1中,至少可以在路由的末尾添加,:format=>false 可在此处找到: 根据第3.11节,路线环球化 例如 这将允许p
constraints :format => "html" do
resources :posts do
resources :comments
end
end
但是,它不会从
rake routes
输出中删除(:format)
部分。在3.1.1中,至少可以在路由的末尾添加,:format=>false
可在此处找到:
根据第3.11节,路线环球化
例如
这将允许params[:pages]包含句点。如果您想要漂亮的URL,并且不喜欢
:format=>false
,您可以尝试以下方法:
# :format must match the empty string
constraints :format => // do
resources :monkeys
end
即使将
与_options
一起使用,:format=>false
选项也很麻烦,尤其是当您有很多路由时。您可以围绕一个范围(Rails 4)包装路由:
我知道我迟到了,但在rails 3.2.13中,这会导致来自curl的请求呈现404错误,我的网站也被google彻底删除了……这正是我要搜索的,非常感谢!顺便说一句,在Rails 5中也工作。在Rails 6中也工作!
# :format must match the empty string
constraints :format => // do
resources :monkeys
end
scope format: false do
# your routes here
end