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.
精彩评论