Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.1 issue with javascript_include_tag in application.html.erb

I've created a clean and simple Rails 3.1 application called demo1. It contains two controllers - hello and goodbye. I get the following error when I try to load http://localhost:3000/say/hello:

ActionView::Template::Error (
  (in /home/me/dev/ruby/demo1/app/assets/javascripts/say.js.coffee)):
    3: <head>
    4:   <title>Demo1</title>
    5:   <%= stylesheet_link_tag    "application" %>
    6:   <%= javascript_include_tag "application" %>
    7:   <%= csrf_meta_tags %>
    8: </head>
    9: <body>
  app/views/layouts/application.html.erb:6:in     
`_app_views_layouts_application_html_erb___558576499_89622220'

The problematic line of application.html.erb is:

<%= javascript_include_tag "application" %>

When I created the application using Rails 3.0 this particular line was:

<%= javascript_include_tag :defaults %>

And this worked fine. In fact, when I change the application.html.erb to use :defaults everything works, but I want to use the new features of Rails 3.1.

I can't seem to turn up anything on Google around this, I guess because Rails 3.1 has just been released.

By the way, I'm following the first chapter in the Agile Web Development with Rails (4th edition) Updated for Rails 3.1 book.

Some environmental info that may help in answering this question:

$ cat /etc/issue
Ubuntu 10.04.2 LTS \n \l

$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]

$ rails -v
Rails 3.1.0

Contents of the say.js.coffee file:

# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
like image 569
ryan Avatar asked Sep 02 '11 10:09

ryan


1 Answers

Ok, I've figured out what the issue was, and so I'll answer my own question.

The problem was the app/assets/javascripts/application.js file contained commented out code. However, one of the commented out lines was as follows:

//= require_tree .

When I delete this line everything works fine.

Hope this helps. If someone can provide some insight as to why the underscore was causing the issue that would be great.

like image 118
ryan Avatar answered Sep 19 '22 01:09

ryan