My require line in application.css.scss isn't working? - ruby-on-rails

I added "jquery_mobile_rails" to my Gemfile and did bundle install. Then I added the following lines to my application.css.scss file:
//=require jquery.mobile
However when I run 'bundle exec rails s' and start my app I get this error:
couldn't find file 'jquery.mobile'
(in /Users/Me/Development/ruby/myapp/app/assets/stylesheets/application.css.scss:1)
I loaded the Rails app console and looked at the assets path config:
Rails.application.config.assets.paths
I get an array of paths which includes my Gemfile path with the jquery_mobile_rails gem and inside the vendor/assets/javascript I see the file jquery.mobile.js.
So why can't I include this in my application.css.scss?

You have mistakenly added the line for javascript(application.js) in the application.css . Please add the following line to your application.css.scss
*= require jquery.mobile

Related

Sprockets::FileNotFound at / couldn't find file 'react-server' with type 'application/javascript'

I'm returning to a website that I made about a year and a half ago, and when spinning up the rails server, I get this error:
Sprockets::FileNotFound at /
couldn't find file 'react-server' with type 'application/javascript'
Checked in these paths: [bunch of file paths...]
The errors looks the same as this issue:
rails web pack react - sprocket couldn't find file react-server
The previous post talks about removing old react rails files, but I don't know which files that would be referring to.
RESOLVED
In the end, it was one installation and one gemfile addition that did the trick. I ran: npm install --save react-server, and then I added: gem 'react-rails', to my gemfile, then of course ran bundle exec install.
In the file server-rendering.js delete or comment those lines:
//= require react-server
//= require react_ujs
//= require ./components

Asset pipeline precompile issue when deploying to heroku

I have built a Rails 4 and I am now trying to deploy to Heroku.
When I run the git push heroku master command, the process shuts down when Heroku runs rake assests:precompile. I get the following error message:
Sass::SyntaxError: Invalid CSS after "... "bootstrap" */": expected "{", was ""
I am at a loss of where to find this error in my code. I have included the bootstrap-sass gem in my gem file, but I have also included the entire css folder from the download provided by Bootstrap in my assets/stylesheets folder.
Below is what I have required in my application.css.sass file:
*= require font-awesome
*= require_tree .
*= require_self
*/
#import "bootstrap-sprockets";
#import "bootstrap";
As a final note, I have also precompiled locally using the rake assets:precompile command. In addition, I have set config.assets.compile equal to true in my application.rb file, as well as uncommenting config.assets.css_compressor = :sass.
Any guidance would be greatly appreciated.
Remove the */ from your code (right below *= require_self). That is what the error is referring to (though it isn't very clear).

manually require 'Bootsy' in assets pipeline Rails 4 application.css vs application.css.scss

I'm using a WYSIWYG called Bootsy. docs here: http://volmer.github.io/bootsy/
I did this command and got:
$ rails generate bootsy:install
route mount Bootsy::Engine => '/bootsy', as: 'bootsy'
create config/locales/bootsy.en.yml
insert app/assets/javascripts/application.js
not found app/assets/stylesheets/application.css not found. You must manually require Bootsy in your assets pipeline.
create config/initializers/bootsy.rb
In my Rails app I do have a file called application.css.scss so the only reason the install couldn't find the file was because of the .scss I'm wondering how to best address this issue.
My first guess was to do this inside my application.css.scss file:
require 'bootsy'
but I'm not sure if I'm supposed to do
*= require_bootsy
or
*= require 'bootsy'
or if I should just add an application.css file inside the pipeline that way it doesn't give me problems. Would that be bad to have an application.css AND an application.css.scss file inside my stylesheets folder?
According to the gem source you should use *= require bootsy
Here's the relevant code from https://github.com/volmer/bootsy/blob/master/lib/generators/bootsy/install_generator.rb
{
original: 'app/assets/stylesheets/application.css',
skip_if: 'require bootsy',
content: "\n *= require bootsy",
position: {
after: '*= require_self'
}
}

Rails 3.2.8 Application.js and Application.css are not working as expcted

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.

when I run rake assets:precompile got couldn't find file 'jquery' in application.js on //= require jquery

when I run
bundle exec rake assets:precompile
I got
couldn't find file 'jquery'
in application.js on line:
//= require jquery
Rails 3.2.2. What is reason?
I'd venture to say you don't have a jquery.js file anywhere in your app. If it's not in app/assets or vendor/assets or lib/assets, add it to one of them -- or if you are using the jquery-rails gem, follow the instructions here.
If you're running in production you must comment out the line
Bundler.require(*Rails.groups(:assets => %w(development test)))
and uncomment the following
Bundler.require(:default, :assets, Rails.env)
since by default gems included in the "assets" group specified in the Gemfile won't be added in the production environment.
This lead me to a similar situation in which I was running a precompile in production but Uglifier kept throwing me a "couldn't find jquery error" but clean compile in development.

Resources