2013-12-15 35 views
0

目前我使用這樣的respond_to`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 }

+0

目前尚不清楚你試圖達到什麼目標,看起來你的第一個例子就是你的問題的答案。 –

+0

你說得對,我的問題一點也不清楚。我調整了我的問題。現在可以理解嗎? – ironsand

回答

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 

參見API documentationthis Railscast有關的詳細信息respond_with