Unexpected Character '#' deploying to Heroku - ruby-on-rails

I'm stuck trying to get my app to work on heroku. I can run locally and it works well, but when I deploy to heroku I get the following error:
2012-05-18T21:26:18+00:00 app[web.1]: (in /app/app/assets/javascripts/application.js.erb)):
2012-05-18T21:26:18+00:00 app[web.1]: 8: <%= render 'layouts/shim'%>
2012-05-18T21:26:18+00:00 app[web.1]: ActionView::Template::Error (Unexpected character '#'
2012-05-18T21:26:18+00:00 app[web.1]: 4: <title><%= full_title(yield(:title))%></title>
2012-05-18T21:26:18+00:00 app[web.1]:
2012-05-18T21:26:18+00:00 app[web.1]: 5: <%= stylesheet_link_tag "application", :media => "all" %>
2012-05-18T21:26:18+00:00 app[web.1]: 7: <%= csrf_meta_tags %>
2012-05-18T21:26:18+00:00 app[web.1]: 3: <head>
2012-05-18T21:26:18+00:00 app[web.1]: 6: <%= javascript_include_tag "application" %>
2012-05-18T21:26:18+00:00 app[web.1]: app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb___39687462904242755_48413880'
2012-05-18T21:26:18+00:00 app[web.1]:
2012-05-18T21:26:18+00:00 app[web.1]:
9: </head>
Initially I thought it was a coffeescript problem. But I have since gotten rid of any .coffee files just to see if it will work. Still, the same result
This is my application.js file:
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require_tree .
$(document).ready(function()
{
function setCountdownTimer(element, year, month, day) {
var date = new Date(year, month, day);
$(element).countdown({until: date});
}
$('#hashtag_id').live('change', function() {
$('#user_comments').empty();
$.ajax({ url: '/headlines/update_comments/',
data: {hashtag: this.value, id: $('#headline_tag').data('id')},
success: function(data) {
$('#user_comments').html(data);
}
})
});
});
Any ideas?

Have you changed any of the coffee script files to just js files, and left the comments at the top in:
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
Remove these comments, if so.

This error occurs often in tandem with another asset pipeline error when Devise is installed. Before investigating the solutions stated here
rails 3.1.0 ActionView::Template::Error (application.css isn't precompiled)
try Snowangel's suggestion first to save time.

Related

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.

Deploying a Rails App to VPS, with NginX Server. Compile Issues

I successfully deployed my rails app to my VPS, but when I try to look at my server from browser, I get a 500 error ("We're sorry, but something's wrong"). The app is working fine locally, so I think the problem lies in not my code but somewhere else.
Here's the log from /current/log/production.log
ActionView::Template::Error (jquery.js isn't precompiled):
4: <title>Songhomme</title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= javascript_include_tag 'jquery' %>
8: <%= csrf_meta_tags %>
9: </head>
10: <body>
app/views/layouts/application.html.erb:7:in `_app_views_layouts_application_html_erb___2525571063257357898_28769560'
I also got the following error:
ActionView::Template::Error (/home/deployer/apps/songhomme/releases/20121204091428/app/views/posts/_posts.erb:27: syntax error, unexpected ',', expecting ')'
...ppend= ( link_to (t.name + " ", '/tags/' + t.id.to_s) );#out...
The code is working fine locally, so I'm not sure what's wrong with the second part of code. For the first part of code, does running rake assets:precompile before I push to my repo solve the problem?
I appreciate your help.
Try declaring your js includes in the manifest file application.js , not by javascript_include_tag. Since Rails version 3 this is the proper way . So , in your application.js :
//= require jquery
//= require jquery_ujs

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

Rails: How do you precompile custom stylesheet for production environment?

I've tried numerous fixes and variations of those fixes that I've found online but none work. My problem is that I have a custom stylesheet that is called if the browser is IE (stylesheet-ie.css.scss). I've ran the following with no success:
rake assets:precompile
I get the following error in production.log after running compile command.
ActionView::Template::Error (stylesheet-ie.css isn't precompiled):
14: <title><%= full_title(yield(:title)) %></title>
15: <%= stylesheet_link_tag "application", media: "all" %>
16: <!--[if IE]>
17: <%= stylesheet_link_tag("stylesheet-ie") %>
18: <![endif]-->
19: <%= javascript_include_tag "application" %>
20: <%= csrf_meta_tags %>
In production.rb I have:
config.assets.precompile += ['stylesheet-ie.css']
The file is assets/stylesheet/stylesheet-ie.css.scss...I had it as stylesheet.css before but changed it trying to get it to work. Neither way works.
At this point I don't know what else to do.
Does this work in development environment?
While doing a precompile, you will have to specify the environment. Are you doing this anywhere?
RAILS_ENV=production rake assets:precompile
This should compile your assets in case you are not mentioning your environment elsewhere.
Hrm.
I have my config/application.rb set up like this:
config.sass.load_paths << File.expand_path('../../lib/assets/stylesheets/')
config.assets.precompile += %w(jquery.animate-colors-min.js ie.js ie8.css)
So it's pretty similar, but you didn't mention the load_paths. (Also, BTW, I'm using .css.sass, so I'm not sure if you'll need to fiddle with config.sass or config.scss.)
—☈

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

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

Resources