samedi 25 juillet 2015

Ruby on Rails: Why doesn't my delete link work?

I am following the Rails guide: http://ift.tt/IsdtVd

and I have the following line in my index.html.erb:

 <%= link_to 'Destroy', team_path(team), method: :delete, data: { confirm: 'Are you sure?' } %>

But it doesn't work; it just goes to the show page.

For your information, this is my routes.rb:

Rails.application.routes.draw do

  get 'bets/index'
  root 'bets#index'
  resources :teams
end

My controller:

def destroy
    @team = Team.find(params[:id])
    @team.destroy
    redirect_to teams_path
end

My application.js:

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree
//= require jquery
//= require jquery_ujs .

My application.html.erb:

<%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'defaults', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>

Please note that I have tried changing <%= javascript_include_tag 'defaults', 'data-turbolinks-track' => true %> to <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>, but this gives me the following error:

 Showing C:/Sites/BettingSite/app/views/layouts/application.html.erb where line #6 raised:

TypeError: Object doesn't support this property or method
(in C:/Sites/BettingSite/vendor/cache/ruby/2.1.0/gems/turbolinks-2.5.3/lib/assets/javascripts/turbolinks.js.coffee)

Line 6 is the line: <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>

Can someone please help me?

Aucun commentaire:

Enregistrer un commentaire