Rails 请教关于 Controller 中所有 Action 都仅使用一个 Layout 渲染的问题

ibachue · April 26, 2012 · Last by iBachue replied at April 26, 2012 · 2267 hits

大家好, 如果希望一个 Controller 中所有 Action 都仅使用一个 Layout 去渲染,而不使用每个 Action 自己的 template,然后我想删除这些无用的 template 文件,但是删除后就显示 Missing template 错误。我试图在 Action 的最后添加 render layout: '....', nothing: true 语句,指定 Layout 但不渲染 template。这个是有效的。但是如果每个 Action 都在最后添加这句语句,就显得冗余。使用 after_filter 是没有用的。Gem 里倒是有一个 before_render_filter,但是看上去版本太老,不兼容现在的 Rails。请教大家,该怎么办?谢谢

@masterwujiang 的指引下,我重新定义了 render 函数,解决了这个问题。

You need to Sign in before reply, if you don't have an account, please Sign up first.