我的许多操作中的应用程序都使用render :nothing => true
。我想要干。默认情况下,如何为特定控制器渲染任何东西?
答案 0 :(得分:0)
您可以执行以下操作:
# put this in a module, or your ApplicationController
def self.nothing_for *actions
before_filter :only => actions do
render :nothing => true
end
end
# This would go in your specific controllers
nothing_for :show, :new, :create
答案 1 :(得分:-1)
这可能会满足您的需求:
before_filter :render_nothing
private
def render_nothing
render :nothing => true
end
before_filter
而不是after_filter
,因为后者在操作完成后执行,这意味着,在内容呈现后。
资料来源:http://ap.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html#M000128