Reputation: 69
I created a new scaffold rails generate scaffold scores score:integer route_id:integer
and ran rake db:migrate
.
This works well, but when I go to the scores page to delete some data the delete link somehow displays the view details, but doesn't delete it. I also compared the link with some other projects and it looks pretty much the same only that it doesn't work this time.
That's what I have in my index.html.erb page:
<td><%= link_to 'Destroy', score, method: :delete, data: { confirm: 'Are you sure?' } %></td>
I found in some posts on this site that the gem file needs to contain gem 'jquery-rails'
so I checked and it is there. I also ran bundle install
again, but no change.
The change from link_to
to button_to
didn't help either.
Does anybody have an idea what else it could be? If you need more details let me know and I will be happy to add it.
Many thanks.
Upvotes: 1
Views: 717
Reputation: 31
I had the same problem and I have managed to solve it only after I have added both jquery and jquery_ujs to my page:
<%= javascript_include_tag "jquery" %>
<%= javascript_include_tag "jquery_ujs" %>
<%= javascript_include_tag "application" %>
I most probably have a problem with the asset pipelines as I have requested both of them in the application.js but it didn't work when they were not explicitly requested on the page. In my application.js I have:
//= require_jquery
//= require_jquery_ujs
//= require_tree .
Upvotes: 1
Reputation: 289
Simple. You need to include jquery_ujs also named as rails.js in your application.html.erb. I have this issue before. Rails needs rails.js to do this.
Upvotes: 0
Reputation: 1976
Sometimes it happens because you haven't included jquery_ujs in your application. Ope the browser console and check if jquery_ujs is included or if it is included multiple times.
Upvotes: 1
Reputation: 452
I'm guessing that the method: :delete
is being overridden or ignored since you're providing the resource. Could you try this?
<td><%= link_to 'Destroy', destroy_score_path(score), data: { confirm: 'Are you sure?' } %></td>
Here is the documentation for link_to
for reference:
http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to
Upvotes: 0