'require_tree .' does not seem to be including the available *.js files as expected. Why?

Hi, all,

Happy new year :slight_smile:

Referring to The Asset Pipeline — Ruby on Rails Guides, it seems that 'require_tree .' in myapp/app/assets/javascripts/ application.js will include all *.js files in the myapp/app/assets/ javascripts/.

I have a few other *.js files in this directory : parts.js, makes.js and categories.js.

Here's an extract from the html file I am viewing:

--------------- Extract start -----------------------

<!DOCTYPE html> <html> <head>   <title>My App</title>

  <script src="/javascripts/jquery.js" type="text/javascript"></

<script src="/javascripts/application.js" type="text/javascript"></

<script src="/javascripts/jquery.min.js" type="text/javascript"></

<script src="/javascripts/jquery_ujs.js" type="text/javascript"></

<!--, "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/ jquery.min.js" %> - "jquery.js", "application.js", "jquery.min.js" , "jquery_ujs.js" -->

<!-- :defaults, "jquery.min.js" -->   <meta content="authenticity_token" name="csrf-param" /> <meta content="jfiFh0CGHgl5F6mX/dORtk1y6IMfnbCavwgx4bVYXbA=" name="csrf-token" /> </head> <body>

--------------- Extract end -----------------------

My 'app/assets/javascripts/application.js' file is:

--------------- Extract start ----------------------- //= require jquery //= require jquery_ujs //= require_tree .

--------------- Extract end -----------------------

My question: I am using rails 3.1.0 and when I open up a page in the webbrowser and view source, I am not seeing the 3 js files above being included. Why are the 3 files not included? Is require_tree broken?

Thank you :slight_smile:

Gordon

I had also clicked on 'application.js' in the line, '<script src="/ javascripts/application.js" type="text/javascript"></script>' in the html file.

It looks like the files in app/assets cannot be accessed.

Here's what the source looks like. Observe the message, 'No route matches [GET] &quot;/javascripts/application.js&quot;<'

---------- Extract of source starts -----------------------

<!DOCTYPE html> <html lang="en"> <head>   <meta charset="utf-8" />   <title>Action Controller: Exception caught</title>   <style>     body { background-color: #fff; color: #333; }

    body, p, ol, ul, td {       font-family: helvetica, verdana, arial, sans-serif;       font-size: 13px;       line-height: 18px;     }

    pre {       background-color: #eee;       padding: 10px;       font-size: 11px;     }

    a { color: #000; }   </style> </head> <body>

<h1>Routing Error</h1> <p><pre>No route matches [GET] &quot;/javascripts/ application.js&quot;</pre></p>

</body> </html>

---------- Extract of source ends -----------------------

WIth the introduction of asset pipeline, should new routes be added to enable files in the app/assets directory to be accessed?

I created a new rails app in my /tmp directory.

I noticed that the Gemfile had something new relating to the asset group.

The app I am working on was created with rails 3.0.x and hence, I made a change to my Gemfile to use rails 3.1.0 and ran "bundle install" to get rails 3.1.0 in.

------ This is what I saw in the Gemfile of a new 3.1.0 app I created (start) -------- # Gems used only for assets and not required # in production environments by default. group :assets do   gem 'sass-rails', " ~> 3.1.0"   gem 'coffee-rails', "~> 3.1.0"   gem 'uglifier' end ------ This is what I saw in the Gemfile of a new 3.1.0 app I created (end) --------

Seeing that and the fact that I use jquery and not coffee script or sass (for css), I altered my own Gemfile of the application which I am encountering a problem with. See below.

------ This is what my current gemfile looks like (start) --------

source 'http://rubygems.org'

gem 'rails', '3.1.0'

gem 'devise' gem 'factory_girl_rails' #, "~> 1.2" gem 'paperclip'

# Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3' gem 'jquery-rails', '>= 1.0.12'

# Gems used only for assets and not required # in production environments by default. group :assets do # gem 'sass-rails', " ~> 3.1.0" # gem 'coffee-rails', "~> 3.1.0"   gem 'jquery-rails', '>= 1.0.12'   gem 'uglifier' end

# clean up test db after each spec test run gem "database_cleaner", "~> 0.6.7"

group :development, :test do     gem "rspec-rails", ">= 2.0.0"     gem "webrat", ">= 0.7.2" end

------ This is what my current gemfile looks like (end) --------

I restarted my server and yet there's still no luck in accessing the assets/javascripts/application.js file in my browser :frowning:

Any ideas?

I looked at 'Upgrading from Old Versions of Rails' in The Asset Pipeline — Ruby on Rails Guides and that has now fixed the problem whereby files in assets/ can now be accessed.

I followed the changes recommended and they worked. Nevertheless, I could not see my custom javascript files in the html when i view its source.

Thank you in advance for any help :slight_smile: