Rails 3 全局渲染 [英] Rails 3 global render
本文介绍了Rails 3 全局渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法让整个控制器渲染特定的部分或文本?
Is there a way to tell an entire controller to render a particular partial or text?
示例:
class PageNotesController < ApplicationController
render :text => "Testing"
def index
@notes = PageNotes.all
end
def show
@note = PageNotes.find(params[:id])
end
def create
@note = PageNotes.create(params[:note])
end
end
现在显然我可以进入每个单独的方法并告诉它渲染某些东西,但我只是想知道这是否可能.
Now obviously I can go into each individual method and tell it to render something, but I was just curious to know if this is possible.
提前致谢!
推荐答案
你可以让整个控制器渲染一个布局.
you can tell an entire controller to render a layout.
layout 'some_layout'
如果您希望控制器呈现相同的动作,那么您可以创建一个动作并将不同的选项传递给它并通过参数条件查找结果.
if you want a controller to render the same action then you can create one action and pass it different options and find results by params conditions.
明确回答您的问题.我不知道.
to explicitly answer your question. I don't know.
这篇关于Rails 3 全局渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文