ActionView::Template::Error (defaults.js isn't precompiled) - ruby-on-rails

Recently, I've been working on migrating my Ruby on Rails site, built on passenger, to a different server, and in the process upgrade rails from 2.3.2 to 3.2. I've installed all necessary gems, and I thought configured everything correctly, but when I go to my site, I get a "We're sorry, but something went wrong" message
I checked the production.log and this is the error message I got:
Connecting to database specified by database.yml
Started GET "/login/login" for ip_address at 2013-05-31 20:12:28 -0400
Processing by LoginController#login as HTML
Rendered login/login.html.erb within layouts/homepage (6.9ms)
Completed 500 Internal Server Error in 43ms
ActionView::Template::Error (defaults.js isn't precompiled):
6:<title>test test test</title>
7: <link rel="icon" type="image/png" href="/images/favicon.ico">
8: <link rel="SHORTCUT ICON" href="/images/favicon.ico"/>
9: <%= javascript_include_tag :defaults %>
10: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
11: <script type="text/javascript" >src="http://cdn.jquerytools.org/1.2.7/full/jquery.tools.min.js"></script>
12: <script type="text/javascript" src="/javascripts/jquery-ui->1.8.20.custom.min.js"></script> <%= stylesheet_link_tag 'home_styles', :media => >'Screen' %>
app/views/layouts/homepage.html.erb:9:in
_app_views_layouts_homepage_html_erb__3199970246383683518_43112000'
I'm still pretty new to Rails, so I'm currently at a bit of a loss what to do. Any help would be appreciated!

<%= javascript_include_tag :defaults %>
This tag is from Rails versions pre 3.1. Are you sure this is what you want to do?
In newer applications, this line is typically including the application JavaScript file instead:
<%= javascript_include_tag "application" %>
This is made possible due to the Asset Pipeline which you can learn about by reading The Asset Pipeline Guide.

Related

Rails production error: ActionView::Template::Error (File to import not found or unreadable: photoshop-drop-shadow

I am facing this photoshop-drop-shadow while running my Rails 4.2 application in production mode.
ActionView::Template::Error (File to import not found or unreadable:
photoshop-drop-shadow. Load paths:
/home/abcuser/Desktop/project/Myproject/app/assets/images
/home/abcuser/Desktop/project/Myproject/app/assets/javascripts
/home/abcuser/Desktop/project/Myproject/app/assets/stylesheets
/home/abcuser/.rvm/gems/ruby-2.3.0/gems/tinymce-rails-4.4.0/app/assets/javascripts
/home/abcuser/.rvm/gems/ruby-2.3.0/gems/tinymce-rails-4.4.0/app/assets/source
/home/abcuser/.rvm/gems/ruby-2.3.0/gems/tinymce-rails-4.4.0/vendor/assets/javascripts
/home/abcuser/.rvm/gems/ruby-2.3.0/gems/remotipart-1.2.1/vendor/assets/javascripts
/home/abcuser/.rvm/gems/ruby-2.3.0/gems/bourbon-4.2.7/app/assets/stylesheets
/home/abcuser/.rvm/gems/ruby-2.3.0/gems/css3buttons-1.0.1/lib/assets/images
/home/abcuser/.rvm/gems/ruby-2.3.0/gems/css3buttons-1.0.1/lib/assets/stylesheets
/home/abcuser/.rvm/gems/ruby-2.3.0/gems/client_side_validations-4.2.5/vendor/assets/javascripts
/home/abcuser/.rvm/gems/ruby-2.3.0/gems/jquery-ui-rails-5.0.5/app/assets/images
/home/abcuser/.rvm/gems/ruby-2.3.0/gems/jquery-ui-rails-5.0.5/app/assets/javascripts
/home/abcuser/.rvm/gems/ruby-2.3.0/gems/jquery-ui-rails-5.0.5/app/assets/stylesheets
/home/abcuser/.rvm/gems/ruby-2.3.0/gems/jquery-rails-4.1.1/vendor/assets/javascripts
/home/abcuser/.rvm/gems/ruby-2.3.0/gems/compass-core-1.0.3/stylesheets):
5: <meta charset="UTF-8">
6: <title><%= Rails.application.config.custom.app_name %></title>
7: <%#= stylesheet_link_tag "marketing" %>
8: <%= javascript_include_tag "application" %>
9: <link rel="stylesheet" href="/marketing/css/vendor/bootstrap.css">
10: <link rel="stylesheet" href="/marketing/css/all.css">
11: <link rel="stylesheet" href="/marketing/css/colorbox.css">
app/assets/stylesheets/report.scss.erb:6
app/views/layouts/public.html.erb:8:in
`_app_views_layouts_public_html_erb__559746694008157479_39976240'
These are my 1st 9 lines in the report.scss.erb:
/* We broke this out of default.css file becuase it inteferring with siilar classes that were overloaded by another dev for the new version of the report/nudge show view */
#import "compass";
#import "bourbon";
#import "photoshop-drop-shadow";
#this is the line it is showing error.
#master-photos-container{height:485px;margin-top:20px;}
#photos #paging-left {float:left;height:205px;width:21px;padding-top:185px;padding-left:15px;}
#photos #paging-right {float:left;height:205px;width:21px;padding-top:185px;}
I am including report.css in application.css as:
*= require report
It is working fine in development mode, I don't know why it is not running production mode.
I am very much worried home page, please help.

Backbone app not initializing on production

I have a Backbone (1.1.0) on Rails (4.1.0) app using RequireJS (requirejs-rails gem) that works fine on my local machine. But when I precompile assets and start the server, the Backbone app, having been compiled/compressed by r.js, does not start. No errors are thrown anywhere. Here are some snippets:
requirejs.yml
paths:
jquery: "jquery/jquery"
underscore: "underscore/underscore"
backbone: "backbone/backbone"
"jquery-mobile": "jquery-mobile-bower/js/jquery.mobile-1.4.2.min"
tpl: "requirejs-tpl/tpl"
"backbone-query-parameters": "backbone-query-parameters/backbone.queryparams"
serializeJSON: "jquery.serializeJSON/jquery.serializejson"
"jqm-config": "jqm-config"
fastclick: "fastclick/lib/fastclick"
shim:
"backbone-query-parameters":
deps: ['backbone']
'jqm-config':
deps: ["jquery-mobile"]
'jquery-mobile':
deps: ["jquery"]
modules:
- name: 'application' # default
tpl:
extension: '.html' # default
application.js
define(["backbone", "./router", "jquery-mobile", "jqm-config", "fastclick"],
function(Backbone, Router) {
var BackboneApp = {
start: function() {
this.router = new Router();
Backbone.history.start();
}
};
return BackboneApp.start();
})
application.html.erb
<!DOCTYPE html>
<html>
<head>
<title></title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= csrf_meta_tags %>
</head>
<body>
hello
<%= yield %>
<%= requirejs_include_tag "application" %>
</body>
</html>
Here's my server logs:
18:57 $ RAILS_ENV=production rails server
=> Booting WEBrick
=> Rails 4.1.0 application starting in production on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
[2014-05-06 19:04:01] INFO WEBrick 1.3.1
[2014-05-06 19:04:01] INFO ruby 2.1.1 (2014-02-24) [x86_64-darwin12.0]
[2014-05-06 19:04:01] INFO WEBrick::HTTPServer#start: pid=60796 port=3000
Started GET "/" for 127.0.0.1 at 2014-05-06 19:04:03 -0500
Processing by MainController#index as HTML
Rendered main/index.html.erb within layouts/application (1.4ms)
Completed 200 OK in 16ms (Views: 13.3ms | ActiveRecord: 0.0ms)
and just to clear up any confusion, here's the html that loads:
<!DOCTYPE html>
<html>
<head>
<title></title>
<link href="/assets/application-34af7785e9260ce67d287c5a05fc3583.css" media="all" rel="stylesheet" />
<meta content="authenticity_token" name="csrf-param" />
<meta content="MjhW2IjblGRfvIsAq/hphJT/WlFckUsQ/jSv8skdysk=" name="csrf-token" />
</head>
<body>
hello
<script>var require = {"baseUrl":"/assets","paths":{"application":"/assets/application-4d1052c11b8765cc7707a5f8643e33bf"},"priority":["application"],"shim":{"backbone-query-parameters":{"deps":["backbone"]},"jqm-config":{"deps":["jquery-mobile"]},"backbone":{"deps":["underscore","jquery"],"exports":"Backbone"}}};</script>
<script data-main="application-4d1052c11b8765cc7707a5f8643e33bf" src="/assets/require-e48b9057622ee54d9d9b4dd773d4f295.js"></script>
</body>
</html>
I am guessing that the mistake is in either how I initialize my app in application.js or in the config in requirejs.yml, but I just can't solve it.
Solved in this issue. Used a require call instead of a define call in my top-level javascript (application.js)

Blank pages after converting to rails 4.1

After converting from rails 3.2 to rails 4.1 it renders blank pages on each action.
Just
Started GET "/" for 127.0.0.1 at 2014-04-17 10:50:59 +0300
Processing by SomeController#index as HTML
Completed 200 OK in 303ms (Views: 0.2ms | ActiveRecord: 1.2ms)
What have I missed in my configs? Route error?
==== UPDATED =====
I have a view in app/views/some/index.html.erb
With code like
somestring code
<script>
somejscode
</script>
rendered html seems to be empty (except chrome addons js):
<html>
<head>
<style type="text/css"></style>
</head>
<body>
<pre style="word-wrap: break-word; white-space: pre-wrap;"> </pre>
<script src="//dl.metabar.ru/static/js/ecomerce-context-sovetnik-vks.js" type="text/javascript" async=""></script>
<iframe src="https://dl.metabar.ru/static/storage/index.html" style="display: none;"></iframe>
</body>
</html>
rails s log is:
=> Booting Thin
=> Rails 4.1.0 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop
Started GET "/" for 127.0.0.1 at 2014-04-17 11:24:02 +0300
Processing by SomeController#index as HTML
Completed 200 OK in 262ms (Views: 0.2ms | ActiveRecord: 5.0ms)
==== UPDATED ====
layout:
<!DOCTYPE html>
<!--[if lt IE 7 ]> <html class="ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]> <html class="ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]> <html class="ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--> <html lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8" />
<!-- Set the viewport width to device width for mobile -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><%= content_for?(:title) ? yield(:title) : "Untitled" %></title>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "vendor/custom.modernizr" %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
<%= javascript_include_tag "application" %>
</body>
</html>
==== UPDATED ====
Seems like it renders something similar to render nothing: true because it renders [" "].
I've made egrep -R "render nothing" . but found nothing helpful. Any suggestions?
render body: File.read("#{Rails.root}/app/views/some/index.html.erb")
Is working, but it's not good decision.
Okay guys, I've fixed it.
I've tried a lot of methods to identify and\or fix this weird bug, but didn't find it.
The last step was
$ cd ..
$ rails new previous_app_name
And used d diff to add rails4 missed configs. And n to skip all changes.
Dirty way, but if you will have such problems and will accurately add or change lines, everything will be good ;)

Cached app issue - deployed with capistrano

I have deployed my app for first time. Cap deploy was successful. However I was getting an error on a specific code segment. So I decided to delete this code segment and get the website up and running first before fixing this error.
I run cap deploy again but I am still getting the same error on the code segment that I removed from the source file (I see the error by tailing production.log). It was not suppose to be there. I searched around on the net and found that the problem is that there is a cached version of the app. I found out that a solution would be to delete the cache-copy folder in /shared folder.
I restarted my services (nginx, unicorn) and open the site again and I still get the same error on the code segment I removed.
I checked my new current folder, cached-copy folder and last release folder and all don't have the code segment that produces the error.
It's really odd to me. Any clue whats going on?
Thanks!
Code segment that produces the error:
ActionView::Template::Error (undefined method `stripe' for #<Rails::Application::Configuration:0x00000002a85578>):
20: <meta name="viewport" content="width=device-width">
21: <%= javascript_include_tag 'application' %>
22: <%= javascript_include_tag "https://js.stripe.com/v1/", type: 'text/javascript' %>
23: <%= javascript_tag "Stripe.publishableKey = '#{Rails.configuration.stripe[:publishable_key]}';", type: 'text/javascript' %>
24: <%= csrf_meta_tag %>
25: <%= stylesheet_link_tag "application", :media => "all" %>
26: <script type="text/javascript" src="//use.typekit.net/xoh2pss.js"></script>
app/views/layouts/application.html.erb:23:in `_app_views_layouts_application_html_erb__486989174473553269_34754060'
The line 23 was removed but its still shown as generating the error.
# config/initializers/stripe.rb
Stripe::API_KEY = 'asd8df9sadf766'
# application.html.erb
<%= javascript_tag do -%>
Stripe.publishableKey = <%= Stripe::API_KEY %>;
<% end -%>
Are your assets precompiled and the old all.js (or similar) being redeployed without this change present? If the routine invoked by the javascript portion isn't present that could produce an error -- that might be the stripe method you're trying to invoke. If they were manually precompiled and you made the change but didn't re-compile it, the redeploy would simply put the old one back out there.

token_error on heroku when I try to load Google API

I am using winston/google_visualr to create nice graphs to visualize statistics in my rails application.
It works fine on my locale system, but if I push it to heroku I get something like a token_error. The result is, that it shows only the Heroku page
We're sorry, but something went wrong.
My head section of application.html.erb looks like this
<head>
<title><%= full_title(yield(:title)) %></title>
<script src='http://www.google.com/jsapi'></script>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
This is the heroku log:
ActionView::Template::Error (Unexpected token name, expected punc (line: 13588, col: 3, pos: 384041)
at expect (/tmp/execjs20121119-2-qx6eku.js:977:40)
Error
at js_error (/tmp/execjs20121119-2-qx6eku.js:505:15)
at new JS_Parse_Error (/tmp/execjs20121119-2-qx6eku.js:497:22)
at token_error (/tmp/execjs20121119-2-qx6eku.js:961:17)
at expect_token (/tmp/execjs20121119-2-qx6eku.js:974:17)
at object_ (/tmp/execjs20121119-2-qx6eku.js:1365:56)
at /tmp/execjs20121119-2-qx6eku.js:1326:51
Completed 500 Internal Server Error in 4980ms
at croak (/tmp/execjs20121119-2-qx6eku.js:954:17)
at maybe_unary (/tmp/execjs20121119-2-qx6eku.js:1425:27)
at expr_ops (/tmp/execjs20121119-2-qx6eku.js:1452:32)
(in /app/app/assets/javascripts/application.js)):
6: <%= stylesheet_link_tag "application", :media => "all" %>
7: <%= javascript_include_tag "application" %>
8: <%= csrf_meta_tags %>
9: <%= render 'layouts/shim' %>
4: <title><%= full_title(yield(:title)) %></title>
5: <script src='http://www.google.com/jsapi'></script>
app/views/layouts/application.html.erb:7:in `_app_views_layouts_application_html_erb__1437494530852335371_34567960'
It looks like that the external script reference may be the reason. Do you have any idea how to implement this?
The demo implementation of the author of the googlevisualr rails extension on heroku works fine. Is there any configuration settings in heroku I need to consider?
Thanks for your help.
It took me a lot of tries but I found the issue.
The error happens if one of the included JS' has syntax errors, i.e. a missing semicolon.
In my Gemfile I didn't add version numbers to my gem '...'.
I was using the gem 'bootstrap-datepicker-rails' in version '0.6.21' for my development environment.
If you push to heroku all your gems will be installed again, with the newest available version. Since version 0.6.28 is the actual version it was installed on heroku. It may have a syntax error and it caused the above issue. So, it had nothing to do with the line
<script src='http://www.google.com/jsapi'></script>
I just corrected the line in my gemfile to the following and all was working then:
gem 'bootstrap-datepicker-rails', '0.6.21'

Resources