Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 禁用:。格式化rails3中的路由_Ruby On Rails_Routing_Formatting_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 禁用:。格式化rails3中的路由

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

您能告诉我如何禁用rails路由中的。:格式选项吗?我只需要html…

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

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