How can I force Rails to precompile SCSS stylesheets? - ruby-on-rails-3

I'm trying to run a CRM gem that is clearly not ready for primetime. I'm trying to contribute back to the project by adding all of the things I'm finding that's wrong with the program.
But I am stuck on an asset precompile issue. I'm about a mile wide and an inch deep on the Asset Pipeline. I have run:
bundle exec rake assets:precompile
but when trying to bring the application up in a browser, the following error is written to the log file:
ActionView::Template::Error (print.css isn't precompiled):
5: %title Not Ready Yet CRM
6: == <!-- #{controller.controller_name} : #{controller.action_name} -->
7: = stylesheet_link_tag :application
8: = stylesheet_link_tag :print, :media => 'print'
9: %style= yield :styles
10:
11: = javascript_include_tag :application
The actual file in the gem is NOT called "print.css". It's called "print.css.scss".
Where do I tell Rails to pick up these files in Asset precompilation? And if I do, will it just automatically know how to interpret SCSS files?

Add it to config.assets.precompile in config/application.rb or config/environments/production.rb.
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
config.assets.precompile += %w( print.css )

Related

Error Compiling Assets Rails 3.2.13

When I go to my rails app in my browser I am getting the following error:
Error Compiling CSS Assets
ArgumentError: no time information in "2013-09-20T10:02:37-05:00"
I have been able to work around this error by clearing the cache and cleaning my assets and restarting Apache. However, I cannot do this anymore.
This is not my first Rails project, but this is the first time I have run into this error, and I cannot figure out how to get around this. I should also add that I have been developing the app for a week now, without this error. I have made no changes to my any of my assets.
I figured I'd add the error message from my logfile.
Completed 500 Internal Server Error in 15066ms
ActionView::Template::Error (no time information in "2013-09-25T12:55:42-05:00"):
2: <html>
3: <head>
4: <title>JournalReview</title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8: </head>
app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb___63165616209989497_70158248592280'
Rendered vendor/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.3ms)
Rendered vendor/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.0ms)
Rendered vendor/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (9.6ms)
Thanks.
I solved this problem. I had overridden the "!" operator to appear as the factorial notation used in math. I had tested this, because I had expected this to interfere with the false logic, I did not expect this to through an error in Time / Date.
Anyway, I removed that operator, from my module, and everything worked.

How do I get jQuery Mobile precompiled for Rails 3 production?

I'm trying to deploy a Rails 3 app which includes jQuery Mobile. It works fine in development, and I understand that it needs to precompile the JS and CSS for production. I'm getting the following error:
Started GET "/orders/mobile" for 127.0.0.1 at Wed Jun 06 14:22:40 -0400 2012
Processing by OrdersController#mobile as HTML
Rendered orders/mobile.html.erb within layouts/mobile (642.9ms)
Completed 500 Internal Server Error in 1122ms
ActionView::Template::Error (jquery.mobile isn't precompiled):
5: <head>
6: <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
7: <title>Company Orders</title>
8: <%= stylesheet_link_tag 'jquery.mobile' %>
9: <%= stylesheet_link_tag 'jquery.mobile.structure' %>
10: <%= stylesheet_link_tag 'jquery.mobile.theme' %>
11: <%= stylesheet_link_tag 'http://fonts.googleapis.com/css?family=Ubuntu' %>
app/views/layouts/mobile.html.erb:8:in `_app_views_layouts_mobile_html_erb__605278794_69818059003840'
app/controllers/orders_controller.rb:330:in `mobile'
app/controllers/orders_controller.rb:329:in `mobile'
I've read the usual stuff, but there are so many things wrong here, I hardly know where to start:
I had the JQM stuff in app/assets, but have since moved them to vendor/assets. They get seen by the precompiler -- I know because it will complain about them on various tries -- but they never seem to get precompiled (in either location).
I've tried *= require_tree ../../../vendor/assets/stylesheets in application.css. I don't really want it included in every page hit, so I'd like to include it in the layout, but I'm just trying to get it precompiled somehow.
I've tried *= require jquery.mobile[[.css].erb] in application.css.
I've tried config.assets.precompile += %w( [[./]vendor/assets/stylesheets/]jquery.mobile.* ) in config/environments/production.rb.
As a last-ditch effort, I've removed the ".erb" from jquery.mobile.css.erb, and removed the <% asset_data_uri %> tags to see if it would compile. It passes the rake assets:precompile command, but still gives me the same error.
I don't want to turn off precompiling for JQM; I want it to work. (I really need to speed this page up.) However, I can't find any guide on how to get JQM elegantly inserted into a Rails 3 app (with precompiling), and I've exhausted every avenue I can think of in trial and error. Surely someone has done this and knows the right way to go about it.
My fundamental problem here is that I need to have some assets precompiled for production, but NOT included in every page hit. Here's what I've figured out:
If I didn't mind JQM being served with every page, I could either put the files in app/assets and let require_tree . do its magic, or leave those files in vendor/assets, and require them individually in application.js. If I want to put them in vendor/assets and NOT specifically require them in application.js, I can use config.assets.paths << "#{Rails.root}/vendor/assets" in production.rb, and (apparently) require_tree in application.js will process this tree as well. This still rolls them up into the compiled application JS "ball," but leaves them distinct on the filesystem.
The proper way to incorporate jQuery Mobile for specific pages -- and keep its files separated in vendor/assets -- seems to be to use both a config.assets.paths << "#{Rails.root}/vendor/assets" directive and a config.assets.precompile += %w( jquery.mobile.* ) directive. This will get the JQM files precompiled, but NOT rolled up into application-(hash).js and application-(hash).css. (They'll be individual files in public/assets.) Then you can do specific javascript_include_tag's and stylesheet_link_tag's in a layout specially for mobile views.
Big finish: I had upgraded to Rails 3.2.5 because I saw some security report on 3.2.3. I rolled back to 3.2.3 and -- incorporating what I learned above -- I was able to finally get it working. I also tried 3.2.4. Apparently there's a regression in > 3.2.3 that interferes with precompiling.

Rails 3 asset pipeline: How to prevent some asset files from being loaded for everyone (eg. browser-specific)

I want to server the 'excanvas.min.js' file only to the Internet Explorer and not to other browsers.
So I did in my application.html.erb:
<!--[if lt IE 9]>
<%= javascript_include_tag 'excanvas.min'
# Excanvas for use of Canvas in IE up to version 8
%>
<![endif]-->
<%= javascript_include_tag 'application' %>
But I get the following error (in production):
Completed 500 Internal Server Error in 3ms
ActionView::Template::Error (excanvas.min.js isn't precompiled)
The error also happens when forcing Rails to precompile the file with
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
config.assets.precompile += %W(excanvas.min.js,other_file.css,even_anotherfile.js)
in 'config/production.rb'. What am I doing wrong?
I could do a
//= require excanvas.min
in the application.js. But that would include the file for every browser...
Info: I made an update from an Rails 3.0-Application.
The problem is in the following line
config.assets.precompile += %W(excanvas.min.js,other_file.css,even_anotherfile.js)
the %W is a shortcut for creating an array, and the items need to be separated by a space. In your case you are adding the string excanvas.min.js,other_file.css,even_anotherfile.js to the precompile list.
So just replace the line as follows:
config.assets.precompile += %W(excanvas.min.js other_file.css even_anotherfile.js)
just try to add <%# %> for line and .
i think they will be displayed as comment.
OR
you can do that will js.judge the browser with js and load the corresponding css file

rails 3 rails couldn't find file 'twitter/bootstrap' pt2

This is my second post regarding this issue as my webrick server spits out this message. I've had this before and twiddled with the application.css file to get it to work. My rails is 3.1.3 on ruby 1.9.3. The response from rails is couldn't find file 'twitter/bootstrap'
"all" %>
Researching on Google I've followed seyhunak's responses on this issue. Here is my line in the Gemfile, on its own line and not in a group.
gem 'twitter-bootstrap-rails', :git => 'http://github.com/seyhunak/twitter-bootstrap-rails.git'
Here is what's in my application.css.scss:
*= require_self
*= require bootstrap_and_overrides
*= require_tree .
Here's what's in my application.js
//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require require_tree .
I have done the following commands:
bundle update
rails g bootstrap:install
rails g bootstrap:layout application fixed
touch bootstrap_and_overrides.css.less
rails s
After restarting the server, I still get that error. I'm unable to get past this.
I think I've exhausted all Stack and Google can suggest. What am I overlooking? thanx, sam
After beating myself up over this, I got some Rails devs to look at this problem. My understanding is that Twitter/Bootstrap needs files to be in the vendor directory. The gem would then need to be removed, commented out, so they would not conflict. My app now shows pages that look like the project's homepage. I'm unsure if I've lost the ability to use less to change things. This is my inexperience showing. Thanks for looking.
Moving gem "twitter-bootstrap-rails" out of group :assets
And doing a bundle install worked for me.
Here is some more information
https://github.com/seyhunak/twitter-bootstrap-rails/issues/91
I have similar problem,
I use application.html.haml instead of application.html.erb
using this link:
HTML to Haml
Code is as:
%html
%head
%title Task
= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true
= javascript_include_tag "application", "data-turbolinks-track" => true
= csrf_meta_tags
%body
= yield
You Must install Haml gem first:
install haml gem rails

rails assets path

I have in
<link href="/assets/application.css" media="screen" rel="stylesheet" type="text/css" />
<script src="/assets/application.js" type="text/javascript"></script>
but when I go to http://localhost:3000/assets/application.css
Routing Error
No route matches [GET] "/assets/application.css"
P.S. Rails 3.1.0.rc4, ruby 1.8.7
Seems Sprockets / Rails 3.1 were acting up for me w/ ruby 1.9.2-p180 ... updating to Ruby-1.9.2-p290 seemed to stop the issue.
Maybe not related to your issue... but useful for anyone else having that issue using those versions of Rails & Ruby.
I found that I had something similar going on after updating to Rails 3.1 this evening. I was working on a project that didn't use ActiveRecord, so I had a modified my application.rb to exclude it. The line that usually reads require 'rails/all' to only include the parts I needed, like this:
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"
This list has changed in Rails 3.1 to include Sprockets, the core component to making the asset pipeline work. I got the asset pipeline serving the serving content as expected by adding this line to the bottom of the list:
require "sprockets/railtie"
After restarting, /assets/application.js and other assets began working as expected.
Note: if you have a custom setup like this, be sure to open the railties gem and look at the contents of lib/rails/all.rb which may have changed (as in this case).
Your scripts and styles will be loaded from the public folder. Drop the assets folder under public and you should be good to go.
In the application layout file, if you have
<%= stylesheet_link_tag "/assets/application" %>
which gives
No route matches [GET] "/assets/application.css"
TRY changing it to
<%= stylesheet_link_tag "application" %>
I had to add the following line in application.rb:
config.assets.enabled = true
in bottom of class Application < Rails::Application