foundation-rails, vendor/modernirz isn't precompiled - ruby-on-rails

I have the same kind of issue as here :
Zurb Foundation 5, modernizr not found
I tried to fix this problem by testing multiple answers from here and from github's related threads, but nothing seems to work.
I'm using "rails", "3.2.15" and foundation-rails", "5.1.1.0"
I receive a 500 error, here is what I found in my production's log file:
Processing by HomeController#index as HTML
Rendered home/index.html.erb within layouts/application (0.9ms)
Completed 500 Internal Server Error in 6.1ms
ActionView::Template::Error (vendor/modernizr.js isn't precompiled):
8:
9: <%= stylesheet_link_tag "application" %>
10: <%= javascript_include_tag "vendor/modernizr" %>
11: <%= csrf_meta_tags %>
12: </head>
13:
14: <body id="bg">
app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___4555789472361352826_33758840'
This is very strange because early in my log file, a line tell me that modernizr is correctly compiled.
....
Compiled application.css (14023ms) (pid 4212)
Compiled vendor/modernizr.js (3ms) (pid 4212)
Compiled active_admin/print.css (307ms) (pid 4212)
...
Here is an extract of my production's environment file:
config.cache_classes = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = true
config.assets.compress = true
config.assets.compile = false
config.assets.digest = true
config.assets.enabled = true
config.assets.version = '1.0'
config.assets.initialize_on_precompile = false
config.cache_store = :memory_store
config.assets.precompile += %w( vendor/modernizr.js )
Thanks in advance for your advice!
PS: everytime I use these commands
rake assets:clean
rake assets:precompile

Try this :
config.assets.compile = true
In application.rb
Then :
I advise you to include the CSS / Less / Js by yourself, this avoid to be dependent on a gem.
You can try something like this : http://www.erikminkel.com/2013/09/01/twitter-bootstrap-3-in-a-rails-4-application/
Pros : You're not dependent on a Gem, for example Foundation update to version from 4 to 5, you just have to update your CSS / LESS / JS files, and you don't have to wait for the gem to be updated.
Cons : The gem give you some helpers that save you a lot of time.
To get those helpers working with your project, you can just copy / paste the helpers from Bootstrap-Gems or Foundation-Gems in your project.

Related

Rails asset paths missing fingerprint in production

We've just deployed a Rails 4.0.3 app to production and have found that asset paths generated by stylesheet_link_tag and javascript_link_tag are missing their fingerprints. So instead of requesting something like application-c841bd1c82c25bb1de8452d2338479f7.js, the page is just request application.js.
RAILS_ENV=production bundle exec rake assets:precompile is successful and generates fingerprinted files.
The bits from config/environments/production.rb that seem relevant are:
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
This is running on our own Apache server, not Heroku. I've looked around quite a bit and found similar problems, but none of the troubleshooting steps for those are helping here. Thanks.
More Information
In case it is helpful, here are the full contents (commented lines removed) of our config files:
application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
module Ctrc
class Application < Rails::Application
config.ceal.application_title = "CTRC Budgeting"
config.encoding = "utf-8"
config.filter_parameters += [:password]
config.active_support.escape_html_entities_in_json = true
config.assets.enabled = true
config.assets.version = '1.0'
config.pmacs_redmine.project_identifier = 'itmat-gcrc'
config.app_data_path = '/data/web/apps/itmat/ctrc'
config.paperclip_defaults = {
path: "/data/web/apps/itmat/ctrc/:attachment/:id/:style/:basename.:extension"
}
if ENV['RAILS_RELATIVE_URL_ROOT']
config.assets.prefix = ENV['RAILS_RELATIVE_URL_ROOT'] + '/assets'
end
end
end
production.rb
Ctrc::Application.configure do
config.cache_classes = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = false
config.assets.digest = true
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.eager_load = true
end
I know that the application is running in production mode because if I set
config.assets.compile = true
in that file, the CSS and JavaScript are compiled and requested correctly.
I'm including those assets in the page like so:
<%= stylesheet_link_tag "application", media: "all" %>
<%= javascript_include_tag "application" %>
but it is still generating links to those assets like this:
<link href="/apps/itmat/ctrc/stylesheets/application.css" media="all" rel="stylesheet">
<script src="/apps/itmat/ctrc/javascripts/application.js"></script>
instead of the fingerprinted links I would expect to see.
I had a similar issue and it turned out to be a problem with the gem AssetSync. Either setting config.assets.compile = true or removing the gem resolved the issue. Compiling assets on the fly and having your Rails serve your assets might be acceptable if you're using a CDN, but generally, taking another approach is usually recommended.
For rails 4.x be sure to set the following:
config/application.rb
config.assets.enabled = true
config.assets.version = '1.0'
config/environments/production.rb
config.assets.compile = false

Understating how assets in Rails 4 work in production

When I run
rake assets:precompile
The compiled assets are written to pubic/assets:
I, [2013-07-21T02:16:00.987988 #13881] INFO -- : Writing /home/jpereira/dev/saleshub/public/assets/glyphicons-halflings-white-62b67d9edee3db90d18833087f848d6e.png
I, [2013-07-21T02:16:01.037698 #13881] INFO -- : Writing /home/jpereira/dev/saleshub/public/assets/glyphicons-halflings-c806376f05e4ccabe2c5315a8e95667c.png
I, [2013-07-21T02:16:01.053630 #13881] INFO -- : Writing /home/jpereira/dev/saleshub/public/assets/marketing/slider-base/slide-01-b85e542137a02bedd6c30dede873ef1e.jpg
I, [2013-07-21T02:16:01.066371 #13881] INFO -- : Writing /home/jpereira/dev/saleshub/public/assets/marketing/slider-base/slide-02-e5106e911d8a0289bfaf2ac64308a640.jpg
I, [2013-07-21T02:16:01.077879 #13881] INFO -- : Writing /home/jpereira/dev/saleshub/public/assets/marketing/slider-base/slide-03-990dccbed4c70f0118b7d30d98094811.jpg
I, [2013-07-21T02:16:01.965560 #13881] INFO -- : Writing /home/jpereira/dev/saleshub/public/assets/application-98713f9763bccfd6bc05dae422d3e242.js
I, [2013-07-21T02:16:02.068469 #13881] INFO -- : Writing /home/jpereira/dev/saleshub/public/assets/application-a40c2cd9b0f20b2a7f3b62d45159fbb3.css
Then, I start the application in production, with:
RAILS_ENV=production rails s
=> Booting WEBrick
=> Rails 4.0.0 application starting in production on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2013-07-21 02:20:49] INFO WEBrick 1.3.1
[2013-07-21 02:20:49] INFO ruby 2.0.0 (2013-06-27) [x86_64-linux]
[2013-07-21 02:20:49] INFO WEBrick::HTTPServer#start: pid=13903 port=3000
But the rendered pages, don't look for the precompiled asses. In the rendered templates I got:
<!DOCTYPE html>
<html>
<head>
<title>App Home Pagetitle>
<link data-turbolinks-track="true" href="/stylesheets/application.css" media="all" rel="stylesheet" />
<link href="/stylesheets/application.css" media="all" rel="stylesheet" />
<link href="/stylesheets/marketing.css" media="all" rel="stylesheet" />
<script src="/javascripts/application.js"></script>
<script src="/javascripts/marketing.js"></script>
<meta content="authenticity_token" name="csrf-param" />
<meta content="8XQYBZWrTxmfdGvQYCK0JwQDfr2pt8si+FjW4a30SsA=" name="csrf-token" />
</head>
<body>
</body>
</html>
The template is the following:
!!! 5
%html
%head
%title App Home Page
=yield(:head)
= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true
= stylesheet_link_tag "application", params[:controller], :media => "all"
= javascript_include_tag "application", params[:controller]
= csrf_meta_tags
%body
=flash_messages(flash)
= yield
My production.rb is as follows:
WebApp::Application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.assets.version = '1.0'
config.log_level = :info
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
end
What I need to configure to have stylesheet_link_tag and javascript_include_tag pick the right assets location on production?
Thanks
I just finished writing a similar question, when yours came up in the related sidebar :)
I found a blog that suggests this is a bug, and is inexplicably mitigated by setting
config.assets.compile = true
In the end I answered my own question.
If your creating assets in subfolders you need to prefix your files with the path to the file:
config.assets.precompile += %w( admin/admin.css admin/admin.js ). You'l find this command commented out in environments/production.rb
setting config.assets.compile = true is a bad idea, its slow and not necessary.
Once you've added your custom assets to config.assets.precompile, run:
bundle exec rake assets:precompile RAILS_ENV=production in the terminal to compile the assets.
I believe you may want to look at the following: that states: Edge Rails Guide
In Rails 4.0, precompiling assets no longer automatically copies non-JS/CSS assets from vendor/assets and lib/assets. Rails application and engine developers should put these assets in app/assets or configure config.assets.precompile.
Further to this I believe you can do specify your JS files by doing the following in your config/application.rb
config.assets.precompile += %w( 'application.js', 'application.css',
#specify CSS or JS files inside here! )
Then execute:
bundle exec rake assets:precompile RAILS_ENV=production

Precompile with compression in development environment

I'd like to run the task
assets:precompile
with compression in development environment.
I've set
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
in development.rb.
But compression with assets:precompile only seems to work in production mode, is that right?
Michael Kastner
For file compress in rails try this following method it will work exactly
My config/environments/development.rb has this, which I interpret the rails guide to mean that assets should be compiled into one file, but not compressed:
`config.assets.compress = false
config.assets.compile = true
config.assets.digest = false
config.assets.debug = false`
Try to add debug: false to your include/link-tags
It work means please
{# in views/layouts/application.html.haml (or .erb, then use <%= %>)}
= stylesheet_link_tag "application", debug: false
= javascript_include_tag "application", debug: false
No need to restart app! I hope you didn't forget to do it after you had changed your development.rb ;-).

application.css.scss file not precompiled

I have seen lots of posts regarding precompiled assets in rails, but I don't think I see one that is related to my specific problem.
My application is complaining that aplication.css.scss is not precompiled.
From what I understand, any *.scss file should be compiled in my rails application when i run:
rake assets:precompile
I even confirmed in my public/assets folder that I can see the compiled application.css file.
However, when I try to visit the first page of my application I get the following error:
Compiled application.css (1002ms) (pid 20298)
Started GET "/" for 10.20.1.162 at 2013-01-21 12:21:38 -0500
Processing by MyController#new as HTML
Rendered business_searches/partials/_form.html.erb (16.6ms)
Rendered business_searches/new.html.erb within layouts/application (45.6ms)
Rendered commons/_documenthead.html.erb (34.0ms)
Completed 500 Internal Server Error in 139ms
ActionView::Template::Error (application.css.scss isn't precompiled):
4: <meta charset="utf-8" />
5: <title>My Company Name | <%= #page_title || 'My Company Tagline' %></title>
6:
7: <%= stylesheet_link_tag "application.css.scss", :media => "all" %>
8: <%= javascript_include_tag "application" %>
9:
10:
app/views/commons/_documenthead.html.erb:7:in `_app_views_commons__documenthead_html_erb___1078677729313377561_30352020'
app/views/layouts/application.html.erb:1:in `_app_views_layouts_application_html_erb___646383708034639720_28260100'
I was able to fix the problem by setting the following variable in my config/environments/production.rb file:
config.assets.compile = true
But according to this post, that is not recommended.
I would advice you to keep your manifest file application.css just for managing css assets , and not to prefix it with .scss . The correct syntax for application.html.erb file is :
<%= stylesheet_link_tag "application", :media => "all" %>
If you've placed some styles in your 'application.css, just create a newcss.scssfile in yourapp/assets/stylesheets` and place them there .
It's because your scss file is having a compile time error. I am quite sure that if you replace it's contents with known valid ones, it will get compiled.
You may comment it and check if it compiles.
Always use 'application.CSS' as base CSS.
Others should be separate.

Rails Assets Not Compiled in Production

Here's the error:
Processing by LandingPageController#index as HTML
Rendered landing_page/index.html.erb within layouts/application (2.1ms)
Completed 500 Internal Server Error in 49ms
ActionView::Template::Error (landing_page.css isn't precompiled):
12: <![endif]-->
13:
14: <%= stylesheet_link_tag "application", :media => "all" %>
15: <%= stylesheet_link_tag params[:controller] %>
16:
17: </head>
18: <body>
app/views/layouts/application.html.erb:15:in `_app_views_layouts_application_html_erb__3002306950342527375_29178380'
I can see that it's looking for the landing_page.css file because of line 15. What I don't understand is what is what is the best way to have this asset precompiled for production. I have tried modifying /config/application.rb:
config.assets.precompile += ['landing_page.css']
This doesn't seem right to me. I'd have to do this for every single stylesheet which would be annoying.
I added code to the application.css manifest:
*= require landing_page
This doesn't seem to work. I get the first error when I do this and don't modify the application config file.
I'm stumped as to how you can include the line
<%= stylesheet_link_tag params[:controller] %>
in your layout and have your assets precompiled for production when you run
bundle exec rake assets:precompile
I feel like I'm missing some simple trick that automatically adds the auto-generated stylesheets and javascript files to the list of files to be precompiled when you run the rake task.
Adding require landing_page to application.css does not cause landing_page to be precompiled. It means that when application.css is precompiled, the contents of landing_page.css will be included in the output.
If you are going to load them individually, ie
    <%= stylesheet_link_tag params[:controller] %>
Then you will need to add them all to the list of things to precompile. You can use wildcards  in that list, so if these controller specific stylesheets were all in stylesheets/controllers then you could do
    config.assets.precompile += ["controllers/*.css"]
Typically though people tend not to do this. While for ease of development things are often split up on a per controller basis, all of these are then required from application.css. Application.css is then the only stylesheet you call stylesheet_link_tag on
in your /config/environments/production.rb add this:
config.assets.precompile += %w( landing_page.css)
This was news to me so I'll share: In Rails 4, only application.js|css manifest files files are auto-compiled by Rails. If you're using something like
javascript_include_tag controller_name
# ex javascript_include_tag 'guitars'
you apparently need to add your custom manifests ('guitars') to config.assets.precompile as mentioned above. I {believe} this is a change from Rails 3.2.

Resources