Запрос AJAX не может увидеть эффект без обновления браузера в Rails

Я столкнулся ста же проблема с этим парнем

Я меняю rjs на js.erb так же, как и он. И мы все используем<%= button_to 'Add to Cart',line_items_path(:product_id => product) ,:remote=>true %> отправить запрос AJAX контроллеру.format.js оштрафовать и выполнить create.js.erb. Но в корзину ничего не добавлялось.

лог результат:

Rendered line_items/_line_item.html.erb (4.3ms) Rendered carts/_cart.html.erb (8.0ms) Rendered line_items/create.js.erb (8.8ms)

Это index.html.erb, который мы отправляем AJAX-запросу.

<% if notice %>
<p id="notice"><%= notice %></p>
<% end %>
<h1>Your Pragmatic Catalog</h1>

<% @products.each do |product| %>
<div class="entry">
<%= link_to image_tag(product.image_url), line_items_path(:product_id => product), html_options = {:method => :post} %>
    <h3><%= product.title %></h3>
    <%=sanitize product.description %>
    <div class="price_line">
      <span class="price"><%= number_to_currency(product.price,:precision=>3) %></span>
      <%= button_to 'Add to Cart',line_items_path(:product_id => product) ,:remote=>true %>
    </div>
  </div>
<% end %>

Это функция контроллера line_items для обработки запроса.

  # POST /line_items
  # POST /line_items.json
  def create
     # for exercise only
    session[:counter] = nil

    @cart = current_cart
    product = Product.find(params[:product_id])
    @line_item = @cart.add_product(product.id)



    respond_to do |format|
      if @line_item.save
        format.html { redirect_to store_index_path }
        format.js
        format.json { render json: @line_item, status: :created, location: @line_item }
      else
        format.html { render action: "new" }
        format.json { render json: @line_item.errors, status: :unprocessable_entity }
      end
    end


  end

create.js.erb

$('#cart').html("<%= escape_javascript(render(@cart)) %>");

Ответы на вопрос(2)

Ваш ответ на вопрос