开发者

Trouble on rendering the template without layout on performing AJAX HTTP requests

I am using Ruby on Rails 3.0.10 and jQuery 1.6. I am trying to handle in a controller action the behavior re开发者_运维知识库lated to the template rendering. I am considering to render or not render a layout based on a parameter request (see the below code for more information).

In my controller the responder is implemented in this way:

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

So, if I browse the http://website.com/articles/1 URL it loads the view template without the layout.

Now, if I perform an AJAX HTTP request like the following

  $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);
    }
  });

it loads the view template with the layout.

Should the AJAX HTTP request populate return the template without the layout? How can I make ?


params[:layout] is a string.

If you don't want any layout, you should pass false, not "false".

So you should use some case statement.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜