Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3.2.2 + jquery mobile :method :delete not working
    text
    copied!<p>I'm using a standard scaffold for my controller:</p> <pre><code># DELETE /addresses/1 # DELETE /addresses/1.json def destroy @address = Address.find(params[:id]) @address.destroy respond_to do |format| format.html { redirect_to addresses_url } format.json { head :no_content } end end </code></pre> <p>My application layout file:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;DemoRailsApp&lt;/title&gt; &lt;link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" /&gt; &lt;script src="http://code.jquery.com/jquery-1.6.4.min.js"&gt;&lt;/script&gt; &lt;script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"&gt;&lt;/script&gt; &lt;%= csrf_meta_tags %&gt; &lt;/head&gt; &lt;body&gt; &lt;div data-role="page" data-theme="a" data-fullscreen="true"&gt; &lt;%= yield %&gt; &lt;/div&gt; </code></pre> <p>index.html.erb</p> <pre><code>&lt;div data-role='header'&gt; &lt;h1&gt;Addreses&lt;/h1&gt; &lt;%= link_to "Add" , new_address_path, "data-icon"=&gt; "plus" , "class" =&gt; "ui-btn-right" %&gt; &lt;/div&gt; &lt;div class="content" data-role="content"&gt; &lt;ul data-role="listview"&gt; &lt;% @addresses.each do |address| %&gt; &lt;li&gt; &lt;%= link_to address.address1, edit_address_path(address) %&gt; &lt;%= link_to 'Destroy', address, confirm: 'Are you sure?', method: :delete, "data-icon" =&gt; "delete" %&gt; &lt;/li&gt; &lt;% end %&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>When I click the delete link, instead of confirming or deleting, the show view is displayed. Very confused.</p> <p><em><strong>Edit2:</em></strong> I added &lt;%= javascript_include_tag 'application' %> to my application.html.erb file and the record was deleted but I now get an error loading the page, and the following from the server:</p> <pre><code>Started DELETE "/addresses/3" for 127.0.0.1 at 2012-04-08 19:32:41 -0500 Processing by AddressesController#destroy as JS Parameters: {"id"=&gt;"3"} Address Load (6.8ms) SELECT "addresses".* FROM "addresses" WHERE "addresses"."id" = ? LIMIT 1 [["id", "3"]] (0.2ms) begin transaction SQL (57.5ms) DELETE FROM "addresses" WHERE "addresses"."id" = ? [["id", 3]] (24.6ms) commit transaction Redirected to http://localhost:3000/addresses Completed 302 Found in 108ms (ActiveRecord: 89.1ms) Started GET "/addresses/3" for 127.0.0.1 at 2012-04-08 19:32:41 -0500 Processing by AddressesController#show as HTML Parameters: {"id"=&gt;"3"} Address Load (0.1ms) SELECT "addresses".* FROM "addresses" WHERE "addresses"."id" = ? LIMIT 1 [["id", "3"]] Completed 500 Internal Server Error in 2ms ActiveRecord::RecordNotFound (Couldn't find Address with id=3): app/controllers/addresses_controller.rb:16:in `show' Rendered /Users/&lt;username&gt;/.rvm/gems/ruby-1.9.3-preview1@railsnexttutorial/gems/actionpack-3.2.2/lib/action_dispatch/middleware/templates/rescues/_trace.erb (3.4ms) Rendered /Users/&lt;username&gt;/.rvm/gems/ruby-1.9.3-preview1@railsnexttutorial/gems/actionpack-3.2.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.2ms) Rendered /Users/&lt;username&gt;/.rvm/gems/ruby-1.9.3-preview1@railsnexttutorial/gems/actionpack-3.2.2/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (16.8ms) Started DELETE "/addresses" for 127.0.0.1 at 2012-04-08 19:32:42 -0500 ActionController::RoutingError (No route matches [DELETE] "/addresses"): actionpack (3.2.2) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' actionpack (3.2.2) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call' railties (3.2.2) lib/rails/rack/logger.rb:26:in `call_app' railties (3.2.2) lib/rails/rack/logger.rb:16:in `call' actionpack (3.2.2) 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.2) 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.2) lib/action_dispatch/middleware/static.rb:61:in `call' railties (3.2.2) lib/rails/engine.rb:479:in `call' railties (3.2.2) lib/rails/application.rb:220:in `call' rack (1.4.1) lib/rack/content_length.rb:14:in `call' railties (3.2.2) lib/rails/rack/log_tailer.rb:14:in `call' rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service' /Users/&lt;username&gt;/.rvm/rubies/ruby-1.9.3- preview1/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service' /Users/&lt;username&gt;/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run' /Users/&lt;username&gt;/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread' Rendered /Users/&lt;username&gt;/.rvm/gems/ruby-1.9.3-preview1@railsnexttutorial/gems/actionpack- 3.2.2/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.7ms) </code></pre> <p><strong><em>Edit:</em></strong> This is the response from the server. I thought delete was DELETE not GET?</p> <pre><code>Started GET "/addresses" for 127.0.0.1 at 2012-04-07 21:26:13 -0500 Processing by AddressesController#index as HTML Address Load (0.9ms) SELECT "addresses".* FROM "addresses" Rendered addresses/index.html.erb within layouts/application (8.7ms) Completed 200 OK in 47ms (Views: 22.2ms | ActiveRecord: 0.9ms) [2012-04-07 21:26:14] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/addresses/1" for 127.0.0.1 at 2012-04-07 21:26:16 -0500 Processing by AddressesController#show as HTML Parameters: {"id"=&gt;"1"} Address Load (0.3ms) SELECT "addresses".* FROM "addresses" WHERE "addresses"."id" = ? LIMIT 1 [["id", "1"]] Rendered addresses/show.html.erb within layouts/application (2.4ms) Completed 200 OK in 7ms (Views: 4.6ms | ActiveRecord: 0.3ms) [2012-04-07 21:26:16] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true </code></pre>
 

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