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 요청이 채워지면 템플릿을 레이아웃없이 반환해야합니까? 어떻게 만들 수 있습니까?