Backbone app not initializing on production - ruby-on-rails

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)

Related

Ckeditor not displayed after installation

After install CKedit dont work. I used the guides - https://github.com/galetahub/ckeditor
I've tried everything but it does not work
config/initializers/assets.rb
`Rails.application.config.assets.precompile += %w(ckeditor/config.js)`
config/initializers/assets.rb
//= require ckeditor/init
routes.rb
mount Ckeditor::Engine => '/ckeditor'
ActiveRecord + carrierwave
gem 'carrierwave'
gem 'mini_magick'
rails generate ckeditor:install --orm=active_record --backend=carrierwave
everything tried, but anyway dont work, help
Here is simple code try this .No need any gems
<head>
<meta charset="utf-8">
<meta name="robots" content="noindex, nofollow">
<title>Full page editing with Document Properties plugin</title>
<script src="https://cdn.ckeditor.com/4.11.2/standard-all/ckeditor.js"></script>
</head>
<body>
<div class="container">
<textarea cols="80" id="editor1" name="editor1" rows="10">
</textarea>
</div>
<script>
CKEDITOR.replace('editor1', {
fullPage: true,
extraPlugins: 'docprops',
// Disable content filtering because if you use full page mode, you probably
// want to freely enter any HTML content in source mode without any limitations.
allowedContent: true,
height: 320
});
</script>
</body>
</html>

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 ;)

How I use helpers in ActionView instance?

How I use helper methods in an ActionView instance?
I create an ActiveView object in Worker to render a layout in background.
I write a helper in helpers directory, but I can't use in layout rendered by my worker:
In app/workers/worker.rb:
av = ActionView::Base.new
av.view_paths = ActionController::Base.view_paths
# ...
av.render :template => "...", layout => "layouts/my_layout"
In app/helpers/my_helper.rb:
module MyHelper
def my_tag(param)
# do something
end
end
In app/views/layouts/my_layout.html.erb:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<%= my_tag "application" %>
</head>
<body>...</body>
</html>
It's this throw error in foreman:
ActionView::Template::Error: undefined method `my_tag' for #<ActionView::Base:0xc3da390>
System:
ruby -v: ruby 1.9.3p448,
rails -v: Rails 3.2.11

ActionView::Template::Error (defaults.js isn't precompiled)

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.

favicon.ico being rendered as part of query parameter; probable route issue

In localhost / WEBrick configuration (Rails 3.1, ruby 1.9.2, one of my routes takes the favicon.ico file as a request parameter. It seems to be only on this one route and am not sure sure why it is doing this:
In my routes:
routes.rb
scope '/arc' do
match '/item/:id' => 'items#show', :as => :item_show # id can be either integer or text
end
In html:
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
Started GET "/arc/item/test-306-some-item" for 127.0.0.1 at 2012-10-18 12:18:18 -0700
...
why is it doing this??? only on the above route?
Started GET "/arc/item/favicon.ico" for 127.0.0.1 at 2012-10-18 12:18:22 -0700
Creating scope :page. Overwriting existing method Item.page.
Processing by ItemsController#show as
Parameters: {"id"=>"favicon"}
Any ideas on why it would be doing this?
Use absolute URI /favicon.ico and then it will work as expected.
You need to give the full path of the favicon
Like
<link rel="shortcut icon" href="/assets/favicon.ico" type="image/x-icon" />
In order to work in all environment like development and production you can use Rails tag for this
<%= favicon_link_tag "favicon.ico" %>
Try:
<link rel="icon" type="image/png" href="<%= image_path("favicon.png") %>" />

Resources