I'm using the angular-rails-templates gem. I have a folder in my /app/assets/javascripts called templates and I have included it in application.js:
//= require_tree ./templates
Inside of templates there is a test.html file with <h1>hello world</h1>.
For some reason, test.html is not being found though, when I log out $templateCache.info() (using app.run) in the console I have:
Object {id: "templates", size: 0}
This turned out to be a sprockets incompatibility (see here)
The short version is:
Add gem 'sprockets', '2.12.3' to your Gemfile
Run bundle update sprockets
Related
I followed stack overfolw's answer
to add adminlte in my rails app
it also says to add
//= require adminlte
in application.js
it works fine on local system but now when I am trying to deploy to digital ocean droplet it gives error
Sprockets::FileNotFound: couldn't find file 'adminlte' with type 'application/javascript'
My gemfile(I removed all gems except relavent) to clear the adminlte issue
source 'https://rubygems.org'
gem 'bundler', '>= 1.8.4'
gem 'pnotify-rails'
source 'https://rails-assets.org' do
gem 'rails-assets-adminlte', '2.3.3'
end
end
I normal cases we write
source 'https://rubygems.org'
gem 'pnotify-rail'
and in application.js
//= require pnotify
and don't include any file like pnotify.js manully
But in this case I instead used
source 'https://rails-assets.org' do
gem 'rails-assets-adminlte', '2.3.3'
end
and for this
//= require adminlte causing issue
From What I understand, you do not have a file named adminlte in your javascript folder.
Your app/assets/javascripts/ must have all the files that you want to require in your application.js
So if you have required adminlte, you must also have a file with the same name in your javascripts folder.
I see that you are using a theme, you might want to consider copying all the javascript and css files to the respective folders. If you have a folder to require, you could use // require_tree ./adminlte which requires all the files in that folder.
I hope this helps :)
I had the same problem, having to import adminlte on some servers and AdminLTE on others.
Just use rails-assets-admin-lte instead of rails-assets-adminlte (they're based on the same code) and import admin-lte instead of adminlte in your CSS and JS application files.
In my application.js file, I have the following:
//= require jquery
//= require vendor
When I load up a Rails server with rails s the application.js file that is served still has the require statements at the top. I expect it to remove these lines and load the jquery file separately.
I'm using Rails 3.2.19. My RAILS_ENV is not set.
Though I'm not entirely sure that what you're doing doesn't work, I typically use //= require [name of js file]. e.g. //= require bootstrap.js when bootstrap.js is inside the vendors/javascript folder.
Are you using an old version of Ruby? Maybe something from before 1.9.3? I had similar before problems when upgrading Rails without upgrading Ruby.
Bug with sprockets 2.2.1
Updated to sprockets 2.2.2 (via bundle update sprockets) and it now works
I have the gem "twitter-bootstrap-rails". And I want to modify some sources files (js && less). Less is importing some files but I don't see where it takes the #import "fontawesome/font-awesome"; from? I don't see them in my app/assets... || vendor/assets...
Edit the gemfile, adding to it the link to local resided gem.
gemfile:
gem 'twitter-bootstrap-rails', :path => '/home/user/git/twitter-bootstrap-rails'
Clone the twitter-bootstrap-rails gem, and issue installation of gems for your project:
$ cd /home/user/git
$ git clone https://github.com/seyhunak/twitter-bootstrap-rails.git
$ cd /your/project/path
$ bundle install
So you can edit then the bootstrap's files.
Run you app with bundler:
$ bundle exec rails s
If you want to use different versions of the javascript files than the ones that come bundled with the gem, the first step is to make sure the following isn't in your application.js:
//= require twitter/bootstrap
When you require 'twitter/bootstrap', it loads all of the individual javascript files for you. Instead, you can specify which ones you want the gem to load for you, and then you can manually require the ones that you have modified.
For example, if your modified source files were in app/assets/javascripts/bootstrap_overrides/, you would do:
//= require twitter/bootstrap/bootstrap-transition
//= require twitter/bootstrap/bootstrap-alert
//= require twitter/bootstrap/bootstrap-modal
//= require twitter/bootstrap/bootstrap-button
//= require twitter/bootstrap/bootstrap-collapse
// ... do this for the remainder of the components you wish to import from the gem
//= require bootstrap_overrides/dropdown.js
//= require bootstrap_overrides/tooltip.js
This will let you use your own modified js instead of what's supplied with the gem. The source for the versions of tooltip.js and dropdown.js included in the gem are available at the gem's github repo: https://github.com/seyhunak/twitter-bootstrap-rails
Also, since these components require jQuery to work, be sure to include them after jQuery in your application.js
Hope this helps!
I think I am missing a vital step:
When installing a gem (ie. bootstrap-wysihtml5) what steps should I take for it to correctly find and reference the javascript and css files.
I add gem bootstrap-wysihtml5 to my gemfile, and run bundle install.
I place //= require bootstrap-wysithtml5 in application.js and *= require bootstrap-wysithtml5 in application.css.
I get the following error:
Error compiling CSS asset
Sprockets::File not found: couldnt find file 'bootstrap-wysihtml5.css'
Do I have to manually copy the js and css to the relevant app/assets file, or is there a crucial step I'm missing?
As Billy said, the correct gem is bootstrap-wysihtml5-rails. The gem installs the JS/CSS without further effort on your part.
Add this to your Gemfile:
gem 'bootstrap-wysihtml5-rails'
Add this to app/assets/javascripts/application.js:
//= require bootstrap-wysihtml5
Add this to app/assets/stylesheets/application.css:
*= require bootstrap-wysihtml5
Note that bootstrap-wysihtml5-rails requires Bootstrap. If you have not already added Bootstrap to your project, follow these steps from the creator of this gem:
In Gemfile, add the following:
gem 'anjlab-bootstrap-rails', :require => 'bootstrap-rails',
:github => 'anjlab/bootstrap-rails'
Rename app/assets/stylesheets/application.css to app/assets/stylesheets/application.css.scss
Add the following to app/assets/stylesheets/application.css.scss:
#import "twitter/bootstrap";
Add the following to app/assets/javascripts/application.js:
//= require twitter/bootstrap
Once the gem & Bootstrap are both installed, initialize wysihtml5.
<textarea id="some-textarea" class='wysihtml5' placeholder="Enter text ..."></textarea>
<script type="text/javascript">
$(document).ready(function(){
$('.wysihtml5').each(function(i, elem) {
$(elem).wysihtml5();
});
});
</script>
I found the solution! Thanks for your help guys.
By moving the position of the javascript references to this order, it now seems to work.
//= require jquery
//= require jquery_ujs
//= require bootstrap-wysihtml5/b3
//= require bootstrap/bootstrap
I have no idea why the order would make such a difference. But it works now! Thanks.
When i try to include
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
The content of the files of the application.css is:
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
*= require social_stream
*= require_tree .
*/
And the content of application.js file is
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require social_stream-base
//= require social_stream-documents
//= require social_stream-events
//= require social_stream-linkser
//= require social_stream-presence
//= require social_stream-oauth2_server
//= require_tree .
my rails app is not including the css and js files those are required in the above snippet.
but when i update the include tags to the specific file those are included fine.
i.e.
<%= stylesheet_link_tag "social_stream" %>
<%= javascript_include_tag "jquery" %>
What i think there is issue of sprockets its not working as expected please advice.
I will be really thankful to you.
It should be ruby version issue. You would be using ruby 2.0.0, try to downgrade to 1.9.2 or 1.9.3. Hope it will work.
Nazar Hussain's answer helped me. It depends on ruby version too. If you are using v.2 then try to downgrade to v.1.9. It is very easy if you are using rvm:
To install v.1.9.3 use:
$ rvm install 1.9.3
To use v.1.9.3 as default:
$ rvm --default use 1.9.3
Then
restart your terminal
install bundler gem
run bundle install
run rake assets:clean RAILS_ENV=development
start your server rails s
That's all.
I was also having this issue but with newer versions of Rails and Ruby.
Examining the log, I was being served javascript.js from Rails cache as the server didn't see a change in the file. I went and moved the require lines around (just one) to tell Rails that there's a change in the file and re-compile/use. Wellm that did it for me!
Hope it helps somebody.
Another important finding is to upgrade your sprockets gem in your Gemfile.
I had version 2.2.1 and had issues, after upgrading to 2.2.2, it worked
gem 'sprockets', '2.2.2'
Are you using sass or less or something similar?
I just had this problem and I found it was because the application.css file contained scss code, which it cannot handle by default.
Simply renaming the file to application.css.scss resolved this issue under Rails 4.2.1.