隐式Rails渲染如何在控制器方法中使用super?

时间:2017-07-20 02:02:08

标签: ruby-on-rails

在下面,隐式渲染是否会在SpecialArticlesController中被调用?或者它会被跳到ArticlesController中的隐式渲染?

class SpecialArticlesController < ArticlesController
  def index
    ...
    super
  end
end

class ArticlesController
  def index
    ...
  end
end

1 个答案:

答案 0 :(得分:0)

除非您显式渲染两次,否则不会出现双重渲染错误。此代码将导致错误:

class ParentController < ApplicationController
  def index
    render
  end
end

class ChildController < ParentController
  def index
    render
    super
  end
end

以下代码不会导致错误:

class ParentController < ApplicationController
  def index
  end
end

class ChildController < ParentController
  def index
    super
    render
  end
end