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

查看:70
本文介绍了是否可以在没有控制器的情况下直接从route.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文件一会儿,而编写控制器对于这种黑客来说实在是太过分了.感谢@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

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

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