首页 文章

没有块参数的`respond_to`

提问于
浏览
1

目前我正在使用这样的 respond_to .

respond_to do |format|
  format.html {render layout: false }
end

我知道像 respond_to {| format | format.html } 这样的句子可以写成 respond_to :html . 但是如果 format.html 也有块参数,我如何在没有第一个块的情况下编写?

我想写像 respond_to :html, {render layout: false } .

1 回答

  • 1

    难道你和 respond_with 混淆了吗?

    class PeopleController < ApplicationController
      respond_to :html
    
      def index
        @people = Person.all
        respond_with @people
      end
    end
    

    respond_with 可以配置为 respond_to

    respond_with(@people) do |format|
      format.html { render layout: false }
    end
    

    有关 respond_with 的更多信息,请参见API documentationthis Railscast .

相关问题