Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add vendor/assets/javascripts to my valid assets route

I'm trying to make this work but it's driving me mad. I already set this in

application.rb

config.assets.paths << Rails.root.join("vendor", "assets", "javascripts").to_s

(.to_s because it returns an object while I want a string in here). I cant find the solution and is driving me mad, because stylesheets directory in vendor works, but javascripts is not.

How can i do this?

Error returned:

<h1>Routing Error</h1>
<p><pre>No route matches [GET] &quot;/assets/ext-all-debug.js&quot;</pre></p>
like image 576
Francesco Belladonna Avatar asked Dec 09 '11 19:12

Francesco Belladonna


People also ask

How do you Precompile an asset?

To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.

What is an asset pipeline?

1 What is the Asset Pipeline? The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages and pre-processors such as CoffeeScript, Sass, and ERB.

What are Rails Sprockets?

Sprockets is a Ruby library for compiling and serving web assets. Sprockets allows to organize an application's JavaScript files into smaller more manageable chunks that can be distributed over a number of directories and files.


1 Answers

I believe vendor is already included in your assets path, check using the rails console

rails console
Rails.application.config.assets.paths.each do |path|; puts path; end

However the easiest thing might be this

  • put ext at app/assets/javascripts/lib
  • require_tree will load it already or be explicit

application.js

//= require ./lib/ext-all-debug.js

If you really want it in vendor

  • create dir vendor/assets/javascripts/ext
  • create manifest file vendor/assets/javascripts/ext/index.js
  • put ext-all-debug.js into vendor/assets/javascripts/ext/

code for index.js

//= require ./ext-all-debug.js

code for application.js

//= require ext

that is the name of the dir that the index manifest file is located

Restart your rails server

if you don't want to load extjs via application.js, i.e. you want to include the extjs lib only on specific pages

<%= javascript_include_tag "ext" %>
like image 143
house9 Avatar answered Sep 18 '22 02:09

house9