0

我的应用程序在很多动作中使用render :nothing => true。我想要干燥。我怎么能说默认情况下不会为特定控制器渲染任何东西?

4

2 回答 2

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
于 2012-05-17T01:55:47.137 回答
-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

于 2012-05-17T00:17:58.087 回答