我可以在没有控制器的情况下直接从 routes.rb 渲染布局吗? [英] Can I Render A Layout Directly From routes.rb, Without A Controller?

查看:25
本文介绍了我可以在没有控制器的情况下直接从 routes.rb 渲染布局吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为网站的管理和公共部分设置一对风格指南.

I would like to set up a pair of style guides for the admin and public sections of a website.

每个都需要自己的布局,其中包含静态 html 和对 erb 部分的调用(因此静态页面不会剪切它).我不需要控制器来为这些页面提供服务,而且我不希望有效的开发内容使其余代码变得混乱.这让我想知道是否有一种方法可以直接渲染布局.

Each will need its own layout which will contain a mixture of static html and calls to erb partials (so a static page won't cut it). I have no need of a controller(s) to serve these pages and I don't want what is effectively development-only content cluttering up the rest of the code. This got me wondering whether there is a way to render a layout directly.

免责声明:我很欣赏这不是我应该经常/永远做的事情,我知道有很多论据说明为什么这是一个坏主意.我对这是否可行很感兴趣.

有没有办法让我直接从 routes.rb 渲染布局而不通过控制器?

Is there a way for me to render a layout directly from routes.rb without going through a controller?

推荐答案

出于某种奇怪的原因,我想渲染一个空白的 JS 文件一段时间,而对于这种 hack 来说,编写控制器感觉太多了.感谢@genkilabs 的回答,我使用了这 3 个班轮:

For some weird reason I wanted to render a blank JS file for a while, and writing a controller felt like too much for this kind of hack. Thanks to @genkilabs 's answer, I used this 3 liner:

get 'analytics/some_file.js', to: -> (env) do
  [200, { 'Content-Type' => 'application/javascript' }, ['']]
end

这篇关于我可以在没有控制器的情况下直接从 routes.rb 渲染布局吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆