0
我正在使用Ruby on Rails 3.0.10和jQuery 1.6。我正在嘗試在控制器動作中處理與模板呈現相關的行爲。我正在考慮根據參數請求呈現或不呈現佈局(有關更多信息,請參閱下面的代碼)。在執行AJAX HTTP請求時呈現沒有佈局的模板時出現問題
在我的控制器響應以這種方式實現的:
def show
respond_to do |format|
format.html { render :layout => params[:layout] } # I am using the 'params[:layout]' (boolean) in order to handle the layout rendering.
end
end
所以,如果我瀏覽它加載視圖模板的http://website.com/articles/1
URL不佈局。
現在,如果我執行像下面
$jQ.ajax({
type: 'GET',
url: '<%= article_url(@article) %>',
data: 'layout=false', # Here I set the parameter 'params[:layout]' so to not render the 'layout' in the related controller action
error: function(jqXHR, textStatus, errorThrown) {
...
},
success: function(data, textStatus, jqXHR) {
...
div_jquery_object.html(data);
}
});
一個AJAX HTTP請求它加載與佈局視圖模板。
如果AJAX HTTP請求填充返回模板沒有的佈局?我該如何製作?