Windows - JRuby on Rails - ActionView::Template::Error invalid encoding - ruby-on-rails

I want to try jruby 1.7.0.RC2 on Windows with Rails 3.2. I'm able to start the server, but each time I try to access a page that requires a css (javascript_include_tag), I get the following error:
invalid encoding in marshaling stream: I"co
Here is the stack trace, if it helps:
ActionView::Template::Error (invalid encoding in marshaling stream: I"◄co):
9: = stylesheet_link_tag "application", :media => "all"
app/views/layouts/application.html.haml:9:in `_app_views_layouts_application_h
tml_haml__357561048_13162'
Rendered C:/jruby-1.7.0.RC2/lib/ruby/gems/shared/gems/actionpack-3.2.8/lib/act
ion_dispatch/middleware/templates/rescues/_trace.erb (7.0ms)
Rendered C:/jruby-1.7.0.RC2/lib/ruby/gems/shared/gems/actionpack-3.2.8/lib/act
ion_dispatch/middleware/templates/rescues/_request_and_response.erb (6.0ms)
Rendered C:/jruby-1.7.0.RC2/lib/ruby/gems/shared/gems/actionpack-3.2.8/lib/act
ion_dispatch/middleware/templates/rescues/template_error.erb within rescues/layo
ut (41.0ms)
My application.css is only the result of the default asset pipeline, nothing fancy. I even get the same error with an empty application.css.scss file...
Everything works fine with Ruby MRI 1.9.2 and 1.9.3.
I must say that when it comes to encoding, I'm clueless. Any idea?

Running rake tmp:clear in the project root dir fixed this issue for me. It seems that jRuby does not like to use MRI Ruby's cached files.

Related

How do I specify a stylesheet for my HTML email with Premailer-Rails gem?

I have a stylesheet I want to use in my HTML emails at the path:
app/vendor/assets/stylesheets/inspinia/email_templates/email-styles.css
I am using the Premailer-Rails gem for my email styling.
In my mailer.html.erb layout, I have the following:
<%= stylesheet_link_tag "inspinia/email_templates/email-styles.css", media: 'all' %>
However, in my logs on Heroku, I get the following message:
app[web.1]: [923202d9-b3f1-4b9a-9f42-7b70dcc01d92] Started GET "/stylesheets/inspinia/email_templates/email-styles.css" for 54.167.56.21 at 2016-12-23 23:25:08 +0000
app[web.1]: [923202d9-b3f1-4b9a-9f42-7b70dcc01d92]
2016-12-23T23:25:08.286725+00:00 app[web.1]: [923202d9-b3f1-4b9a-9f42-7b70dcc01d92] ActionController::RoutingError (No route matches [GET] "/stylesheets/inspinia/email_templates/email-styles.css"):
So how do I figure out/specify the correct path for this stylesheet in production?
try move email-styles.css to /public/assets/ folder, or add it to the assets pipeline.
Premailer-rails wiki:
File System: If there's a file inside public/ with the same path as in the URL, it is read from disk. E.g. if the URL is http://cdn.example.com/assets/email.css the contents of the file located at public/assets/email.css gets returned if it exists.
Asset Pipeline: If Rails is available and the asset pipeline is enabled, the file is retrieved through the asset pipeline. E.g. if the URL is http://cdn.example.com/assets/email-fingerprint123.css, the file email.css is requested from the asset pipeline. That is, the fingerprint and the prefix (in this case assets is the prefix) are stripped before requesting it from the asset pipeline.
Add the following into config/initializers/assets.rb:
Rails.application.config.assets.precompile << 'email-styles.css'
Rails.application.config.assets.paths << Rails.root.join('app/vendor/assets/stylesheets/inspinia/email_templates')
Then use <%= stylesheet_link_tag 'email-styles.css', media: 'all' %> in the template.

Ruby on Rails, image compilation and precompilation

I just deployed a rails app and I am having an error when I load a page saying:
We're sorry, but something went wrong.
In the production.log I see that message:
Started GET "/" for 128.179.252.130 at 2014-11-30 08:32:28 +0000
Processing by StaticPagesController#home as HTML
Rendered static_pages/home.html.erb within layouts/application (0.4ms)
Rendered layouts/_shim.html.erb (0.0ms)
Rendered layouts/_header.html.erb (2.4ms)
Completed 500 Internal Server Error in 4ms
ActionView::Template::Error (./icons/icon_nameplate.png isn't precompiled):
37:<ul class="dropdown-menu">
38:
39:<li>
40: <%= menu_dropdown('Profile', "./icons/icon_nameplate.png", "Nameplate Icon", current_user) %>
41:</li>
So I believe the error comes from this part of the message:
./icons/icon_nameplate.png isn't precompiled
I searched the internet, found three possible solution, none of which did work:
1. config.assets.compile = true (in production.rb file)
2. config.assets.precompile += %w[*.png *.jpg *.jpeg *.gif] (still in production.rb file)
3. bundle exec rake assets:precompile RAILS_ENV=production
All of this changed absolutely nothing, and the website still shows the same error. So I am turning for you to help.
Thank you very much in advance.
What finally did the trick for me is completely restart the rails app. This is described in the link below.
The recommended version did the trick for me which is:
Create (or update) a file called restart.txt in the tmp folder of your Rails application on the server.
After that no problem at all.
Cheers

incomplete "\n" on UTF-16LE Error

I have been trying to follow several tutorials on rails and each time I am hitting the following issue at the time of running rails s:
Started GET "/" for 127.0.0.1 at 2014-09-14 06:57:44 +0100
Connecting to database specified by database.yml
Processing by CarsController#index as HTML
Car Load (1.0ms) SELECT "cars".* FROM "cars"
Rendered cars/index.html.erb within layouts/application (396.0ms)
Completed 500 Internal Server Error in 101655ms
ActionView::Template::Error (incomplete "\n" on UTF-16LE
(in /cygdrive/c/rails/todolist/3/rails-angular-example-master/app/assets/javascripts/angular_app.js.coffee.erb)):
3: <head>
4: <title>Angular</title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8: </head>
9: <body>
app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb__988651031__1054838708'
app/controllers/cars_controller.rb:6:in `index'
config/initializers/quiet_assets.rb:8:in `call_with_quiet_assets'
Tutorial:https://github.com/wulftone/rails-angular-example
This occurs when ExecJS tries to process your assets (javascript and coffeescript) and your file encoding is not UTF-16LE.
Most popular fix: use an alternative ExecJS runtime
Probably the most popular fix is to use NodeJS as your ExecJS runtime. One way to do so:
Install nodejs
Set an environment varaible EXECJS_RUNTIME to Node
Start up your Rails server
Alternative fix: modify existing configuration
Alternative to making another installation (NodeJS) is to modify the configuration of your default ExecJS runtime. I believe your system is using cscript.
Have a look at your execjs runtimes.rb file. (It is in your gems directory.) You can see the latest version of this file on github here. It contains the following:
JScript = ExternalRuntime.new(
name: "JScript",
command: "cscript //E:jscript //Nologo //U",
runner_path: ExecJS.root + "/support/jscript_runner.js",
encoding: 'UTF-16LE' # CScript with //U returns UTF-16LE
)
I can't advise you on the best course to take, but for the sake of getting a fix in place quickly, you may want to just edit this file (then restart your server).
You may find that removing the //U fixes the problem.
You may find that changing UTF-16LE to UTF-8 fixes the problem.
You may find that the combination of both of these steps fixes the problem.
These instructions are drawn from ExecJS::RuntimeError on Windows trying to follow rubytutorial

javascript_include_tag Rails 4 generating "/javascripts/" instead of "/assets" in production

I have a Rails 4 application with
<%= javascript_include_tag "modernizr", "data-turbolinks-track" => true %>
in the head. In development, the following HTML is rendered, and modernizr is loaded:
<script data-turbolinks-track="true" src="/assets/modernizr.js?body=1"></script>
In production, the followign HTML is rendered, and modernizr is not loaded (404 not found):
<script data-turbolinks-track="true" src="/javascripts/modernizr.js"></script>
In production, /assets/modernizr.js is found and browsable.
The Rails documentation says that the javascript_include_tag should generate
<script data-turbolinks-track="true" src="/assets/modernizr.js?body=1"></script>
In production, my stylesheet_link_tags are fine, linking to the /assets/ directory.
Why is the javascript_include_tag linking to /javascripts instead of /assets in production, and how can I fix it?
One of the usage statements for AssetUrlHelper indicates it will produce /javascripts/ urls
like what you are seeing:
# asset_path "application", type: :javascript # => /javascripts/application.js
(from asset_url_helper.rb line 117 - [1])
This code looks like it can only be reached if the precompiled asset is missing
so it would appear that your asset compilation is not working (my deployments usually
fail when that happens, so maybe yours isn't even firing).
The same asset_url_helper.rb calls the /javascripts/ part 'extname' and
uses the following map to know how to generate the name:
# Maps asset types to public directory.
ASSET_PUBLIC_DIRECTORIES = {
audio: '/audios',
font: '/fonts',
image: '/images',
javascript: '/javascripts',
stylesheet: '/stylesheets',
video: '/videos'
}
A new Rails 4 app has this in the config/environments/production.rb
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
which seems to match the behavior you are seeing.
By default, Rails only precompiles application.js, application.css and any images it finds in the assets path. Therefore, in production mordernizr will not get precompiled and thus the javascript helpers will not be able to find the file.
In order to fix the issue, you can add modernizr to the precompile list by modifying the following config in production.rb
config.assets.precompile += ['modernizr.js']
For more information see the Rails Guides
Be sure to precompile your assets in production by running this command:
RAILS_ENV=production bundle exec rake assets:precompile
The Rails Guide on the asset pipeline can give you more details: http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets
I have a new application using Rails 4 deployed on Heroku with :
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
my javascript application.(fingerprint).js called from the src: assets/application.js
i think your problem come from something into your production.rb who define assets from another location.
So maybe you can add Moderniz.js to
config.assets.precompile = ['.js', '.css', '*.css.erb']
in config/production.rb
Or simply require modernizr script into your application.js
//= require mordernizr
and remove the modernizr script call into your layout.
<%= javascript_include_tag "modernizr", "data-turbolinks-track" => true %>
Can you check from where your application.js is served into your production environment ?
It may be because this file needs to be in /vendor/assets/javascript instead of /app/assets/javascript. The Vendor folder is for javascript libraries, and the App folder is for your code.
A better solution than adding a tag to your layout would be adding a script reference to your application.js and let the sass compiler compress and attach it to your main javascript file.
If you don't get a definitive answer, check out:
http://guides.rubyonrails.org/asset_pipeline.html#asset-organization

TZInfo::InvalidTimezoneIdentifier with rails 3.1.0 and ubuntu

Here is the error in log file when making initial http connection to the server. It is odd that sometime the server can render a http connection without any problem. But more often with the TZinfo error.
Started GET "/" for 98.206.231.173 at 2011-11-13 09:41:34 +0800
Processing by SessionsController#new as HTML
Rendered sessions/new.html.erb within layouts/sessions (2.2ms)
Completed 200 OK in 4ms (Views: 3.4ms | ActiveRecord: 0.0ms)
TZInfo::InvalidTimezoneIdentifier (no such file to load -- tzinfo/definitions/Etc/UTC):
Any suggestion to fix it? Thanks.
how do you serve your Rails application? Mongrel? Unicorn? ...? can you restart your app, to make sure that all threads have the same config?
Do you have 'tzinfo' listed as a dependency in your Gemfile?
Which version of TZinfo are you using? Can you try to update TZInfo to the latest version?
e.g. run bundle update
all the newer versions of TZInfo, like 0.3.30 , have the directory lib/tzinfo/definitions/Etc with the UTC.rb definition in it as follows:
$ more .rvm/gems/ruby-1.9.2-p0/gems/tzinfo-0.3.30/lib/tzinfo/definitions/Etc/UTC.rb
module TZInfo
module Definitions
module Etc
module UTC
include TimezoneDefinition
timezone 'Etc/UTC' do |tz|
tz.offset :o0, 0, 0, :UTC
end
end
end
end
end
What do you see underneath your .rvm/gems/RUBY-VERSION/gems/ directory? which TZInfo are you using? and is the UTC.rb file there? Are the permissions on the directory and the file 'world readable'?
Maybe it's related to this:
http://rubyglasses.blogspot.com/2008/05/converting-timezone-to-tzinfotimezone.html

Resources