asset pipeline error but config.assets.enabled = false in application.rb - ruby-on-rails

I am deploying a first rails app via capistrano with:
rails 3.1
passenger 3.0.11
nginx 1.0.10
The app errors out. In my $app/logs/production.log, I get:
5: <%= stylesheet_link_tag "application" %>
6: <%= javascript_include_tag "application" %>
7: <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
8: <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.js"></script>
app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb__88091947956529734_37470040'
But in my application.rb, I have set:
# Enable the asset pipeline
config.assets.enabled = false
I thought this directive causes the asset pipeline to be disabled. Any ideas what is going on?

With the pipeline disabled, Rails is expecting the referenced files application.css and application.js to be available in the public directory at the pre-3.1 locations.
Is there a reason why you are not using the pipeline?

Related

Rails not serving static files

I'm running the latest version of Thin, Rails, and Ruby. The relevant parts of my build script are:
export RAILS_ENV=production
export RAILS_SERVE_STATIC_FILES=true
# generate static assets
RAILS_ENV=production rake assets:precompile
# restart server
rails server thin -d
And in my production.rb I have
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
And I include these files in my view using
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>
This successfully compiles my assets and moves them to the /public/assets folder. However, none of these assets are actually served when loading the page. The generated HTML is
<link rel="stylesheet" media="all" href="/stylesheets/application.css" />
<script src="/javascripts/application.js"></script>
These don't have the digests included in the filename, so I believe they're incorrect. Attempting to manually load the filenames both with and without their digest included all fail with a 404 as well. What am I doing wrong?
put the js files under app/assets/javascript.
put the css files under app/assets/stylesheets.
All your js and css files are loaded in the header of application.html.erb, which loads the application.css and application.js. This is what these two lines of code does.
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>
These two files, there is a line require_tree . which loads all the files in the corresponding directory:
app/assets/javascript
app/assets/stylesheets
I usually use public folder only for external libraries when I am not using a CDN. And you will need to explicitly include them in the application.js and application.css file.

Ruby on Rails + Passenger unable to load cached assets

I just installed passenger and I believe I got it working, but now my rails application seems to be unable to load cached assets. When attempting to load a page I get this message:
ActionView::Template::Error (No such file or directory - /home/glawson/vidStream/tmp/cache/assets/sprockets%2Ff1663d34d4b6003379113df98f1433a520130421-27670-18ux0pw.lock):
2: <html>
3: <head>
4: <title>VidStream</title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8:
app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb___4187138815701226714_20468720'
This happens when I try to run my webapp with passenger or in development with rails server. I'm a little fuzzy on what the error even means other than it can't find a file that it's looking for.
In production mode you need to precompile the asset directory using
RAILS_ENV=production rake assets:precompile
Then only it will work. Because by default for prod asset precompile is enabled.

Mapstraction Precompilation Error in Rails 3.1

I have a Rails 3.1 application with assets set up to pre-compile in production (Heroku, in this case). This includes jQuery, jQueryUI and Mapstraction. Running heroku logs, however, reveals that Mapstraction, a mapping JS library, may not be pre-compiling successfully:
2012-10-25T05:13:11+00:00 app[web.1]: ActionView::Template::Error (mxn.js?(googlev3) isn't precompiled):
2012-10-25T05:13:11+00:00 app[web.1]: 8: <%= javascript_include_tag :application %>
2012-10-25T05:13:11+00:00 app[web.1]: 9: <%= csrf_meta_tag %>
2012-10-25T05:13:11+00:00 app[web.1]: 11: <%= javascript_include_tag "mxn.js?(googlev3)" %>
2012-10-25T05:13:11+00:00 app[web.1]: 12: <script type="text/javascript">
2012-10-25T05:13:11+00:00 app[web.1]: 10: <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
I suspect that since Mapstraction (mxn.js) is being constructed with a geodata service provider name as a parameter that Rails might not be able to handle that. It works locally in a dev environment though, without precompiling. Any ideas on why precompiling would fail in this case?
You can manually include the necessary files to make Mapstraction work with the Rails asset pipeline:
curl https://raw.github.com/mapstraction/mxn/master/source/mxn.js > vendor/assets/javascripts/mxn.js
curl https://raw.github.com/mapstraction/mxn/master/source/mxn.core.js > vendor/assets/javascripts/mxn.core.js
curl https://raw.github.com/mapstraction/mxn/master/source/mxn.openlayers.core.js > vendor/assets/javascripts/mxn.openlayers.core.js
then you put
//= require mxn
//= require mxn.core
//= require mxn.openlayers.core

Asset Pipeline on Rails 3.1.4 - Javascripts with right path but Stylesheets with wrong path

My Asset Pipeline seems to be broken...
It happened after an upgrade:
rails from '3.1.0' to '3.1.4'
compass-rails from '1.0.0.rc.3' to '1.0.2'
compass from '0.12.rc.1' to '0.12.1'
On <head> JS's are under /assets/ (correct path), but CSS's are going under /stylesheets/ (wrong path). Real example:
<link href="/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css">
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
My application.html.erb file:
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
How can I make 'styleesheet_link_tag' point to /assets/ instead of /stylesheets/?
EDIT
It was the mobile-fu gem, version 0.3.0 that was causing this odd behaviour.
I'm not using it anymore and problem is gone.
Can you add this to the application.erb file and check once?
config.assets.prefix = "/assets"
Check your config/compass.rb file. There maybe a css_path setting in there.

Rails 3.1 CSS file loading twice?

I'm using Rails 3.1 RC. I wanted to load a CSS manually and not via the asset pipeline.
I've tried it like this and with a hand coded tag:
<%= stylesheet_link_tag "application" %>
<%= stylesheet_link_tag "/stylesheets/global" %>
For some reason FireBug shows me multiple get requests for the global.css file:
Rails bug? Me being stupid?
If anyone is wondering - I use CSSEdit a lot so couldnt work with the file inside the asset pipeline.
did you set the assets.enabled to false in config/application.rb?
# Enable the asset pipeline
config.assets.enabled = false
I would guess this is caused by the same problem as described in Rails 3.1 with Asset Pipeline, link_to :confirm message showing twice?.
You have precompiled assets in your development environment and <%= stylesheet_link_tag "application" %> will expand into multiple tags including each CSS file, one of them being global.css.

Resources