2

I am following the Rails guide: http://guides.rubyonrails.org/getting_started.html

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?

  • 1
    You have `jquery` and `jquery_ujs` required twice in your `application.js` file. Try removing the second ones. – Ryan K Jul 25 '15 at 18:42
  • try this `<%= link_to 'Destroy', team, method: :delete, data: { confirm: 'Are you sure?' } %>` – Athar Jul 25 '15 at 18:42
  • Thanks for your advice (both Ryan K and Athar), I've just tried those suggestions, they didn't work –  Jul 25 '15 at 18:43
  • 1
    Also make sure you spell "application" correctly. It seems like your `javascript_include_tag` misspells "application" (it reads "applicationn"). Also, what is on line 18 of `application.js`? – Ryan K Jul 25 '15 at 18:46
  • 1
    And a third thing: make sure that there is a period after require_tree. Like this: `//= require_tree .` – Ryan K Jul 25 '15 at 18:48
  • @RyanK, thank you for pointing that out, I have edited my question accordingly and updated the error message. I don't know what the code is on line 18 in `application.js` but I have seen it advised to use here http://stackoverflow.com/questions/18154916/rails-4-link-to-destroy-not-working-in-getting-started-tutorial –  Jul 25 '15 at 18:49
  • @RyanK I also just tried the `//= require_tree .` but no joy –  Jul 25 '15 at 18:50
  • can you try one more thing please.. remove these `//= require jquery` and `//= require jquery_ujs .` from the end and simply add `.` after tree. also please share the rake routes output. – Athar Jul 25 '15 at 18:51
  • As per the error message check this link.. it might help http://stackoverflow.com/questions/28882182/rails-coffeescript-typeerror-object-doesnt-support-this-property-or-method – Pavan Jul 25 '15 at 18:53

1 Answers1

0

So it seems like the problem is that Windows is not working well with CoffeeScript. According to this question, add this gem to your gemfile:

gem 'coffee-script-source', '1.9.1'

That, or remove all CoffeeScript from your code by renaming your .coffee or .js.coffee files to regular .js files (and, of course, changing your CoffeeScript code to regular JavaScript). You would also have to remove any CoffeeScript gems from your gemfile.

BTW, when you update your gemfile, you must run bundle install and then restart your server.

Community
  • 1
  • 1
Ryan K
  • 3,985
  • 4
  • 39
  • 42
  • I've just tried the first part and it hasn't worked, I can't see where I have any `.coffee` or `.js.coffee` files –  Jul 25 '15 at 19:09
  • 1
    It would be under `app/assets/javascripts`. – Ryan K Jul 25 '15 at 19:11
  • Yeah I can't see any in there –  Jul 25 '15 at 19:17
  • 1
    So if you're not going to use Coffeescript (which I would still try to use, but if it doesn't work...), then remove the CoffeeScript gem (I believe its `coffee-rails`) and the `coffee-script-source` gem, run `bundle install`, and restart your server. – Ryan K Jul 25 '15 at 19:21
  • 1
    Ok, so I just re-read the error message. It's having problems with the `turbolinks` gem (which uses coffeescript). Replace the line `//= require turbolinks` with `// require turbolinks`. – Ryan K Jul 25 '15 at 19:26
  • 1
    Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/84277/discussion-between-ryan-k-and-benjs-1). – Ryan K Jul 25 '15 at 19:29