My current code looks like this:
<%= javascript_include_tag "hchq.js", "bootstrap-image-gallery.js", "bootstrap-image-gallery.min.js", "load-image.min.js", "media.js", "jquery", "bootstrap.js", "jquery.dataTables.js", "DT_bootstrap.js" %>
<%= javascript_include_tag :defaults %>
However, I keep getting:
ActionController::RoutingError (No route matches [GET] "/assets/defaults.js"):
actionpack (3.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.8) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.8) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.8) 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.8) 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.8) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.8) lib/rails/engine.rb:479:in `call'
railties (3.2.8) lib/rails/application.rb:223:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.8) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
/usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/usr/local/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
Digging into the problem more I found: Rails 3.1rc4 defaults.js not found that suggested I take defaults line out. I take it out and the 404 goes away, but with it in and with it out I can't issue a delete request. It just directs me to the show page.
Any idea on what's going on and how can I solve this so I don't get the 404 and can issue a delete request?
Update:
Here is the actual delete link: <%= link_to 'Delete', client_path(client), method: "delete", class: "label label-important" %>
which produces the following html: <a href="/clients/2" class="label label-important" data-method="delete" rel="nofollow">Delete</a>
which seems right to me.
and here is the line from the log:
Started GET "/clients/2" for 127.0.0.1 at 2012-09-27 16:50:23 -0500
Processing by ClientsController#show as HTML
Parameters: {"id"=>"2"}
Client Load (0.3ms) SELECT "clients".* FROM "clients" WHERE "clients"."id" = ? LIMIT 1 [["id", "2"]]
Rendered clients/show.html.erb within layouts/application (1.2ms)
Completed 200 OK in 47ms (Views: 45.4ms | ActiveRecord: 0.3ms)
Started GET "/assets/defaults.js" for 127.0.0.1 at 2012-09-27 16:50:23 -0500
Served asset /defaults.js - 404 Not Found (4ms)
Another thing I tried is getting rid of the defaults line, as that is pre-rails 3.1, and using "application" as the only thing inside the javascript_include_tag and I still have this issue.
The only plausible explanation has to do with the CRSF token Rails forms expect when having a non-GET action coming to hit the server. When you build a form in rails, you have a token that is passed to the server for purpose of security. This is automatically built-in when you use the form_for
and form_tag
helpers (forms uses POSTS and stuff).
Because of the protect_from_forgery
in your application_controller
, rails don't let you do POST/DELETE/PUT from outside a form, that's why the link_to
doesn't work, it is just a link, trying to do a POST. But if you comment this line, the link would work just fine.
More info here: http://guides.rubyonrails.org/security.html#cross-site-request-forgery-csrf