Note that there are some explanatory texts on larger screens.

plurals
  1. PORails not making Ajax request
    primarykey
    data
    text
    <p>Having a very odd problem. I am following the <em>Agile Web Development with Rails (2nd edition)</em> and am currently on the Ajax request iteration. </p> <p><strong>The Problem:</strong> My Application isn't making an AJAX request instead just redirecting to the store_path. </p> <p>My Line Items create actions looks as follows:</p> <pre><code> def create @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_url) } format.js format.xml { render :xml =&gt; @line_item, :status =&gt; :created, :location =&gt; @line_item } else format.html { render :action =&gt; "new" } format.xml { render :xml =&gt; @line_item.errors, :status =&gt; :unprocessable_entity } end end end </code></pre> <p>And the add to cart looks like this:</p> <pre><code> &lt;%= button_to 'Add to Cart', line_items_path(:product_id =&gt; product),remote: true %&gt; </code></pre> <p>Producing the following form:</p> <pre><code>&lt;form action="/line_items?product_id=3" class="button_to" data-remote="true" method="post"&gt;&lt;div&gt;&lt;input type="submit" value="Add to Cart"&gt;&lt;input name="authenticity_token" type="hidden" value="euZKvTy2ioSTITELTb06ErJZfSeGBuzoMhUyHROvgjI="&gt;&lt;/div&gt;&lt;/form&gt; </code></pre> <p>I have also placed the create.js.rjs in view/line_items directory with the following content:</p> <pre><code>page.replace_html('cart', render(@cart)) </code></pre> <p><strong>EDIT: SERVER LOG</strong><br> Hmm...seems like there is an error in the <code>&lt;%= javascript_include_tag :defaults %&gt;</code> </p> <pre><code>Started GET "/" for 127.0.0.1 at 2013-01-23 17:43:05 -0800 Processing by StoreController#index as HTML Product Load (0.2ms) SELECT "products".* FROM "products" ORDER BY title Cart Load (0.1ms) SELECT "carts".* FROM "carts" WHERE "carts"."id" = ? LIMIT 1 [["id", 22]] Rendered store/index.html.erb within layouts/application (7.6ms) LineItem Load (0.3ms) SELECT "line_items".* FROM "line_items" WHERE "line_items"."cart_id" = 22 Product Load (0.2ms) SELECT "products".* FROM "products" WHERE "products"."id" = 3 ORDER BY title LIMIT 1 Product Load (0.2ms) SELECT "products".* FROM "products" WHERE "products"."id" = 4 ORDER BY title LIMIT 1 Rendered line_items/_line_item.html.erb (6.7ms) Rendered carts/_cart.html.erb (12.4ms) Completed 200 OK in 34ms (Views: 29.2ms | ActiveRecord: 1.1ms) [2013-01-23 17:43:05] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/assets/depot.css?body=1" for 127.0.0.1 at 2013-01-23 17:43:05 -0800 Served asset /depot.css - 304 Not Modified (0ms) [2013-01-23 17:43:05] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/assets/defaults.js" for 127.0.0.1 at 2013-01-23 17:43:05 -0800 Served asset /defaults.js - 404 Not Found (6ms) ActionController::RoutingError (No route matches [GET] "/assets/defaults.js"): actionpack (3.2.9) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' actionpack (3.2.9) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call' railties (3.2.9) lib/rails/rack/logger.rb:32:in `call_app' railties (3.2.9) lib/rails/rack/logger.rb:16:in `block in call' activesupport (3.2.9) lib/active_support/tagged_logging.rb:22:in `tagged' railties (3.2.9) lib/rails/rack/logger.rb:16:in `call' actionpack (3.2.9) lib/action_dispatch/middleware/request_id.rb:22:in `call' rack (1.4.1) lib/rack/methodoverride.rb:21:in `call' rack (1.4.1) lib/rack/runtime.rb:17:in `call' activesupport (3.2.9) lib/active_support/cache/strategy/local_cache.rb:72:in `call' rack (1.4.1) lib/rack/lock.rb:15:in `call' actionpack (3.2.9) lib/action_dispatch/middleware/static.rb:62:in `call' railties (3.2.9) lib/rails/engine.rb:479:in `call' railties (3.2.9) lib/rails/application.rb:223:in `call' rack (1.4.1) lib/rack/content_length.rb:14:in `call' railties (3.2.9) lib/rails/rack/log_tailer.rb:17:in `call' rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service' /usr/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service' /usr/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run' /usr/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread' Rendered /var/lib/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.1ms) Started GET "/assets/logo.png" for 127.0.0.1 at 2013-01-23 17:43:05 -0800 Served asset /logo.png - 304 Not Modified (2ms) [2013-01-23 17:43:05] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/assets/ruby.jpg" for 127.0.0.1 at 2013-01-23 17:43:05 -0800 Served asset /ruby.jpg - 304 Not Modified (0ms) [2013-01-23 17:43:05] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/assets/rtp.jpg" for 127.0.0.1 at 2013-01-23 17:43:05 -0800 Served asset /rtp.jpg - 304 Not Modified (0ms) [2013-01-23 17:43:05] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/assets/wd4d.jpg" for 127.0.0.1 at 2013-01-23 17:43:05 -0800 Served asset /wd4d.jpg - 304 Not Modified (0ms) [2013-01-23 17:43:05] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started POST "/line_items?product_id=3" for 127.0.0.1 at 2013-01-23 17:43:35 -0800 Processing by LineItemsController#create as HTML Parameters: {"authenticity_token"=&gt;"euZKvTy2ioSTITELTb06ErJZfSeGBuzoMhUyHROvgjI=", "product_id"=&gt;"3"} Cart Load (0.1ms) SELECT "carts".* FROM "carts" WHERE "carts"."id" = ? LIMIT 1 [["id", 22]] Product Load (0.1ms) SELECT "products".* FROM "products" WHERE "products"."id" = ? ORDER BY title LIMIT 1 [["id", "3"]] LineItem Load (0.1ms) SELECT "line_items".* FROM "line_items" WHERE "line_items"."cart_id" = 22 AND "line_items"."product_id" = 3 LIMIT 1 (0.1ms) begin transaction (0.2ms) UPDATE "line_items" SET "quantity" = 28, "updated_at" = '2013-01-24 01:43:35.930200' WHERE "line_items"."id" = 56 (158.5ms) commit transaction Redirected to http://0.0.0.0:3000/ Completed 302 Found in 168ms (ActiveRecord: 159.1ms) Started GET "/" for 127.0.0.1 at 2013-01-23 17:43:36 -0800 Processing by StoreController#index as HTML Product Load (0.3ms) SELECT "products".* FROM "products" ORDER BY title Cart Load (0.1ms) SELECT "carts".* FROM "carts" WHERE "carts"."id" = ? LIMIT 1 [["id", 22]] Rendered store/index.html.erb within layouts/application (6.1ms) LineItem Load (0.2ms) SELECT "line_items".* FROM "line_items" WHERE "line_items"."cart_id" = 22 Product Load (0.2ms) SELECT "products".* FROM "products" WHERE "products"."id" = 3 ORDER BY title LIMIT 1 Product Load (0.2ms) SELECT "products".* FROM "products" WHERE "products"."id" = 4 ORDER BY title LIMIT 1 Rendered line_items/_line_item.html.erb (4.7ms) Rendered carts/_cart.html.erb (8.8ms) Completed 200 OK in 28ms (Views: 23.5ms | ActiveRecord: 1.0ms) Started GET "/assets/depot.css?body=1" for 127.0.0.1 at 2013-01-23 17:43:36 -0800 Served asset /depot.css - 304 Not Modified (0ms) [2013-01-23 17:43:36] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/assets/defaults.js" for 127.0.0.1 at 2013-01-23 17:43:36 -0800 Served asset /defaults.js - 404 Not Found (4ms) ActionController::RoutingError (No route matches [GET] "/assets/defaults.js"): actionpack (3.2.9) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' actionpack (3.2.9) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call' railties (3.2.9) lib/rails/rack/logger.rb:32:in `call_app' railties (3.2.9) lib/rails/rack/logger.rb:16:in `block in call' activesupport (3.2.9) lib/active_support/tagged_logging.rb:22:in `tagged' railties (3.2.9) lib/rails/rack/logger.rb:16:in `call' actionpack (3.2.9) lib/action_dispatch/middleware/request_id.rb:22:in `call' rack (1.4.1) lib/rack/methodoverride.rb:21:in `call' rack (1.4.1) lib/rack/runtime.rb:17:in `call' activesupport (3.2.9) lib/active_support/cache/strategy/local_cache.rb:72:in `call' rack (1.4.1) lib/rack/lock.rb:15:in `call' actionpack (3.2.9) lib/action_dispatch/middleware/static.rb:62:in `call' railties (3.2.9) lib/rails/engine.rb:479:in `call' railties (3.2.9) lib/rails/application.rb:223:in `call' rack (1.4.1) lib/rack/content_length.rb:14:in `call' railties (3.2.9) lib/rails/rack/log_tailer.rb:17:in `call' rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service' /usr/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service' /usr/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run' /usr/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread' Rendered /var/lib/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.7ms) Started GET "/assets/ruby.jpg" for 127.0.0.1 at 2013-01-23 17:43:36 -0800 Served asset /ruby.jpg - 304 Not Modified (0ms) [2013-01-23 17:43:36] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/assets/logo.png" for 127.0.0.1 at 2013-01-23 17:43:36 -0800 Served asset /logo.png - 304 Not Modified (0ms) [2013-01-23 17:43:36] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/assets/wd4d.jpg" for 127.0.0.1 at 2013-01-23 17:43:36 -0800 Served asset /wd4d.jpg - 304 Not Modified (0ms) [2013-01-23 17:43:36] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/assets/rtp.jpg" for 127.0.0.1 at 2013-01-23 17:43:36 -0800 Served asset /rtp.jpg - 304 Not Modified (0ms) [2013-01-23 17:43:36] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload