false" to correctly display the js.erb template in Rails 2.3.3 I am running the last branch of Rails 2-3-stable (cur...">

To call "render: layout => false" to correctly display the js.erb template in Rails 2.3.3

I am running the last branch of Rails 2-3-stable (currently 2.3.3).

I am using jQuery to send an AJAX request to my "create" action, in which I have the following block:

respond_to do |format|
  format.js
end

I created create.js.erband to verify this action I added the following line:

alert('hello');

The request correctly enters the format.js block, but the answer tries to display the layout. Here is my log:

Jul 22 20:44:27 [2970] INFO: Rendering template within layouts/application
Jul 22 20:44:27 [2970] INFO: Rendering contacts/create

If I change my block respond_toto the following, it will work:

respond_to do |format|
  format.js { render :layout => false }
end

Is this the expected behavior or is it a bug in Rails? I would think that the fact that I am executing a JS response would be enough to set the layout to false.

+3
4

Ajax on Rails , , .

, , .

http://dev.rubyonrails.org/ticket/3229

, , .

+1

:

class ApplicationController < ActionController::Base
  # this is needed to prevent XHR request form using layouts
  before_filter proc { |controller| (controller.action_has_layout = false) if controller.request.xhr? }

. onliner .

~ 1 , .

+10

, , - :

///application.js.erb

<%= yield -%>

, js , . , js , , - jQuery UI onLoad.

+2

JQuery, AJAX POST, "false". , . :

postFormData: function () {
  $('#form_id').submit(function () {
    $.post($(this).attr('action'), $(this).serialize(), null, 'script');
    return false;
  });
}

, false.

0

Source: https://habr.com/ru/post/1713280/


All Articles