中级Ramaze路由请帮忙

发布于 2024-09-24 04:32:29 字数 463 浏览 1 评论 0原文

第 1 部分:

我调用了 layout(:default){|path,wish| Wish !~ /rss|atom|json/} 但对 /foo/bar.json 的请求似乎认为 wishhtml 并使用该布局。我该如何解决这个问题?

第 2 部分:

我想路由 /path/to/file.ext,以便它调用映射到 /path 的控制器上的方法 to并在制定回报时使用ext。有没有比将 'file.ext' 传递给 to 方法、解析它并执行案例更好(更优雅)的方法?如果我写下“如何使用 Ramaze 进行 REST?”,这个问题会更简洁。似乎有一个 Google 网上论坛对此问题的答案,但由于某种原因我无法访问它。

Part 1:

I have a call to layout(:default){|path,wish| wish !~ /rss|atom|json/} but requests to /foo/bar.json seem to think wish is html and uses the layout anyway. How can I fix this?

Part 2:

I want to route /path/to/file.ext so that it calls the method to on the controller mapped to /path and uses ext when formulating the return. Is there a better (more elegant) way to do this than passing the 'file.ext' to the to method, parsing it, and doing cases? This question would have been more succinct if I had written, how does one do REST with Ramaze? There appears to be a Google Groups answer to this one, but I can't access it for some reason.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

女皇必胜 2024-10-01 04:32:29
class ToController < Controller

  map '/path/to'
  provide( :json, :type => "application/json") { |action, val| val.to_json } 

  def bar
    @barInfo = {name: "Fonzie's", poison: "milk"}
  end

end

当您请求 /path/to/bar.json 时,此控制器返回纯 JSON,并在您请求 /path/to/bar 时使用布局+视图包装(Ramaze 没有默认布局设置,本例中的布局来自于Controller父类)。

class ToController < Controller

  map '/path/to'
  provide( :json, :type => "application/json") { |action, val| val.to_json } 

  def bar
    @barInfo = {name: "Fonzie's", poison: "milk"}
  end

end

This controller returns plain JSON when you request /path/to/bar.json and uses the layout+view wrapping when you request /path/to/bar (Ramaze has no default layout setting, the layout in this example comes from the Controller parent class).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文