Deploying to Heroku: CodeRay is not Precompiled - How to remove? - ruby-on-rails

I'm learning Rails and read about using CodeRay to have lovely syntax highlighting in your page. When I use rails server it's fine and everything is hunky dory, but when I try to deploy to Heroku I get the useful "something went wrong" page. According to the logs, ActionView::Template::Error (coderay.css isn't precompiled):. So I want to remove CodeRay from my Rails app for now.
I removed the CSS file, the link in the erb file, CodeRay from my Gemfile, ran bundle install and bundle update for good measure, but I still get the same error.
2012-05-27T07:41:22+00:00 app[web.1]: Completed 500 Internal Server Error in 98ms
2012-05-27T07:41:22+00:00 app[web.1]:
2012-05-27T07:41:22+00:00 app[web.1]: 2: <html>
2012-05-27T07:41:22+00:00 app[web.1]: 3: <head>
2012-05-27T07:41:22+00:00 app[web.1]: ActionView::Template::Error (coderay.css isn't precompiled):
2012-05-27T07:41:22+00:00 app[web.1]: 5: <%= stylesheet_link_tag "application", "coderay", :media => "all" %>
2012-05-27T07:41:22+00:00 app[web.1]: 4: <title>RG Simms</title>
2012-05-27T07:41:22+00:00 app[web.1]: 6: <%= javascript_include_tag "application" %>
2012-05-27T07:41:22+00:00 app[web.1]: 7: <%= csrf_meta_tags %>
2012-05-27T07:41:22+00:00 app[web.1]: 8: <link rel="/favicon.ico" alt="gentlemanraptor">
Now, this is really weird. I have removed the stylesheet_link_tag to coderay in the html.erb, uninstall the actual gem completely, and deployed to Heroku again, but with the same error.
Currently using the cedar stack and rails 3.2.3.
Am I doing something wrong?

You need to tell rails to precompile coderay.css along with your other assets:
# application.rb
config.precompile += %w(coderay.css)
Try that.
If it still doesn't work you probably need to remove the stylesheet link tag to coderay, since it will get bundled with your application.rb during asset precompilation

You need to compile your assets locally first.
Take a look here: https://devcenter.heroku.com/articles/rails3x-asset-pipeline-cedar
Try the below before pushing to Heroku.
RAILS_ENV=production bundle exec rake assets:precompile

Related

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

delayed_job rails gem error on heroku, maybe bootstrap related?

For some reason, simply installing the gem delayed_job_active_record causes my heroku app to crash.
I've run the following steps:
Added to gem file:
gem "delayed_job_active_record"
Terminal:
bundle install
rails generate delayed_job:active_record
rake db:migrate
git add .
git commit -m "added delayed_job gem"
git push
git push heroku master
heroku run rake db:migrate
heroku ps:scale worker=1
Everything installs without an error, but then when I load the page, my heroku logs show the following:
WARN: tilt autoloading 'sass' in a non thread-safe way; explicit require 'sass' suggested.
2012-07-07T19:47:14+00:00 app[web.1]: 5: <%= stylesheet_link_tag "application", :media => "all" %>
2012-07-07T19:47:14+00:00 app[web.1]: 8: <%= yield :head %>
2012-07-07T19:47:14+00:00 app[web.1]: (in /app/app/assets/stylesheets/custom.css.scss)):
2012-07-07T19:47:14+00:00 app[web.1]: 2: <html xmlns:fb="http://ogp.me/ns/fb#">
2012-07-07T19:47:14+00:00 app[web.1]: app/assets/stylesheets/custom.css.scss:1
2012-07-07T19:47:14+00:00 app[web.1]:
2012-07-07T19:47:14+00:00 app[web.1]: Completed 500 Internal Server Error in 1465ms
2012-07-07T19:47:14+00:00 app[web.1]:
2012-07-07T19:47:14+00:00 app[web.1]: Load path: /app
2012-07-07T19:47:14+00:00 app[web.1]: 7: <%= csrf_meta_tags %>
2012-07-07T19:47:14+00:00 app[web.1]: app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb__1868084818636776228_47102160'
2012-07-07T19:47:14+00:00 app[web.1]: ActionView::Template::Error (File to import not found or unreadable: bootstrap.
When I uninstall the gem, the program goes back to having no errors. I also don't have any problems if I run on localhost. The error happens only when I load the delayed_job gem (even if I do nothing else aside from install it)
Any help would be appreciated!
Thank you.
For anyone in the future that would like to know...this solved it:
Add the following to application.rb:
config.assets.initialize_on_precompile = false

passenger-install-apache2-module to run several applications on one server. Something not right

I've configured an Ubuntu server with passenger-install-apache2-module so that I can run several rails applications on one server. I've got a test application running which works fine using webbrick, but when I restart the apache server, I get the "We're sorry, but something went wrong" error. When I place a file in /public/index.html, that is rendered fine but as soon as the application relies on rails to generate content, I get the same error.
Where can I find the logs so I can find out more information? Or does anyone have a better idea?
UPDATE: I chmodded the log file, and now get this error in the production log:
Started GET "/users" for 77.100.43.95 at 2012-07-06 07:38:48 +0000
Processing by UsersController#index as HTML
Rendered users/index.html.erb within layouts/application (4.2ms)
Completed 500 Internal Server Error in 115ms
ActionView::Template::Error (application.css isn't precompiled):
2: <html>
3: <head>
4: <title>Max</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___1047297680506537616_22545860'
app/controllers/users_controller.rb:7:in `index'
Thanks
Try running
bundle exec rake assets:precompile
from within the application directory. This should fix the error.

Rails Error In Production, may due to link_tag and precompilation

I have installed rails 3.1 with apache2 and passenger on ubuntu 10.04. using ruby 1.9.2 with RVM.
When I load the application in browser in production (development version works fine on my machine), it does not work.
My Production Error Log is:
Started GET "/articles" for 117.230.75.50 at 2011-09-12 13:51:34 +0000
Processing by ArticlesController#index as HTML
Rendered articles/index.html.erb within layouts/application (56.4ms)
Completed 500 Internal Server Error in 126ms
ActionView::Template::Error (application.css isn't precompiled):
2: <html>
3: <head>
4: <title>Youexpress</title>
5: <%= stylesheet_link_tag "application" %>
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__385712067674585148_29380260'
app/controllers/articles_controller.rb:7:in `index'
But, when I remove the link_tags in app/views/layouts/application.html.erb like this, the application works fine in production mode.
<!DOCTYPE html>
<html>
<head>
<title>Youexpress</title>
</head>
<body>
<%= yield %>
</body>
</html>
How do I get Around this? When I do bundle exec rake assets:precompile I get the following error:
rake aborted!
no such file to load -- uglifier
(in /home/username/youexpress/vendor/bundle/ruby/1.9.1/gems/jquery-rails-1.0.14/vendor/assets/javascripts/jquery-ui.min.js)
Note: In the above error it shows ruby/1.9.1 not 1.9.2 ( I've installed 1.9.2 )
Please help with my situation.
Thanks
I've found the answer myself, The reason for the error is rails app needs javascript runtime for certain features of sass, coffeescript and uglifier to work.
There are many ways to solve this, by installing javascript runtimes like nodejs
But, the solution I went with, and perhaps the easiest one is, adding gem 'therubyracer' to my Gemfile and then running bundle install
Excerpt from my Gemfile is below
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'therubyracer'
gem 'sass-rails', " ~> 3.1.0"
gem 'coffee-rails', "~> 3.1.0"
gem 'uglifier'
end
adding therubyracer also fixes rake assets:precompile
Hope this helps. I've spent days searching for this solution.

Resources