Topic: RJS and HTTP Responses

Hi all!

I'm using link_to_remote with :method => :delete in a REST-based app.

Everything works fine (the object is destroyed in the database, and the destroy.rjs loads). Even in log, I can see:

Processing LinksController#destroy (for 127.0.0.1 at 2007-07-20 12:34:35) [DELETE]
  Session ID: 1016ffb8d829dad8e6db207414281f7f
  Parameters: {"_method"=>"delete", "action"=>"destroy", "id"=>"7", "controller"=>"links"}
  User Columns (0.013217)   SHOW FIELDS FROM users
  User Load (0.044538)   SELECT * FROM users WHERE (users.`id` = 1) LIMIT 1
  Link Columns (0.013695)   SHOW FIELDS FROM links
  Link Load (0.004172)   SELECT * FROM links WHERE (links.`id` = 7)
  SQL (0.000349)   BEGIN
  Link Destroy (0.002653)    DELETE FROM links
WHERE `id` = 7

  SQL (0.011558)   COMMIT
Rendering links/destroy
Completed in 0.16638 (6 reqs/sec) | Rendering: 0.02313 (13%) | DB: 0.09018 (54%) | 200 OK [http://localhost/links/7/destroy]


But, when looking to HTTP response returned (using Firebug) I get weird errors, like routing error and so on.

<h1>Routing Error</h1>

<p><pre>no route found to match &quot;/links/7/destroy&quot; with {:method=&gt;:get}</pre></p>


As we can see from this response, it does an GET method. But, log shows us, that destroy action was called successfull.

I know it's working, but, it's weird. And I can't test RJS methods from the response!

Anyone knows why? Is that a bug?

Re: RJS and HTTP Responses

Hmm.. Looks like FireBug does a new HTTP Request when checking Response.

Using curl -X DELETE, it returned the Javascript just fine, but, I can't test it.

Here are my test:

def test_should_destroy_and_remove_link
  assert_difference "Link.count", -1 do
    delete :destroy, :id => 1
    assert_response :success
    assert_rjs :remove, "link_1"
  end
end

Here's the test error

remove with args [link_1] does not show up in response:
$("link_1").remove();.
<nil> is not true.

And here's the response from curl:

GeekMac:~/Sites/Rails/tgeist arthur$ curl -X DELETE http://localhost:3001/links/13/destroy
try {
  $("link_13").remove();
} catch (e) {
  alert('RJS error:\n\n' + e.toString()); alert('$(\"link_13\").remove();'); throw e
}
GeekMac:~/Sites/Rails/tgeist arthur$