Liquid::Template... is not visible in the mailer erb file - ruby-on-rails

I'm receiving this error:
Class#new_employee_survey_email failed with ActionView::Template::Error: uninitialized constant ActionView::CompiledTemplates::Liquid ..
The liquid gem is installed. I can use it in views or in the rails console. I can't get it to work in the email template only.
That template have only several html tags and the call to the Liquid class from their example:
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
</head>
<body>
<% #template = Liquid::Template.parse("hi {{name}}") # Parses and compiles the template %>
<%= #template.render( 'name' => 'tobi' ) %>
</body>
</html>
The email is send by delay job if this makes difference.
I will apreciate any help in making this work.

I found the solution:
The jem was successfully found after restarting my box.
Possible reasons - the terminal that had "rake jobs:work" running was not aware of the installation and the addition of the Liquid gem to my gem file.
To not look like complete newby ... :(
I have restarted the rake server and the gem started working on all views/controlers but the mailers
I have restarted the the rake job, but not the console that it is running on ...
I hope this helps others to not waste time ... I'm still feeling newb thought :( ...

Related

ActionMailer and Rspec: Unable to find a browser command (Rails 5.2)

I have upgraded rails 4.2.11.1 to 5.2.8.1, and ActionMailer stopped working within Rspec.
When I run this simple welcome email (described on their page):
UserMailer.with(user: #user).welcome_email.deliver_now
It returns the following internal server error (500):
Unable to find a browser command. If this is unexpected,
Please rerun with environment variable LAUNCHY_DEBUG=true
or the '-d' commandline option and file a bug at
https://github.com/copiousfreetime/launchy/issues/new
I have the following configuration:
config.action_mailer.delivery_method = :test
When running with the env var LAUNCHY_DEBUG=true it returns:
InternalMailer#welcome_email: processed outbound mail in 10.0ms
Sent mail to admin#example.com (18.2ms)
Date: Thu, 26 Jan 2023 18:52:30 +0000
From: example#example.com
To: example#example.com
Message-ID: <63d2cbee2134b_d2ad277028a04983aa#238604b1f73f.mail>
Subject: Welcome to My Awesome Site
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1> testing</h1>
</body>
</html>
The same happens if I try to run it within a controller.
Did I miss any breaking changes?

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

Gem server not serving gemspec.rz

I've setup a local gem server for my group on the internal network, and it serves most gems fine, except annotate which needs the gemspec.rz and my server returns a 404 every time it hits it.
I do have the annotate gem installed on the gem server with its quick/marshal/gemspec under specifications, I even manually setup a quick/marshal in the "root" dir, nothing works.
When I do gem generate_index it simply wipes the quick/marshal dir
When I do a bundle install from a dev machine with the local gem server (x.x.x.x) as source, this is what I get
Fetching source index from http://x.x.x.x:8808/
Resolving dependencies...
Net::HTTPNotFound: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
<HEAD><TITLE>Not Found</TITLE></HEAD>
<BODY>
<H1>Not Found</H1>
`/quick/Marshal.4.8/annotate-2.4.1.beta1.gemspec.rz' not found.
<HR>
<ADDRESS>
WEBrick/1.3.1 (Ruby/2.0.0/2013-11-22) at
x.x.x.x:8808
</ADDRESS>
</BODY>
</HTML>
# wget http://x.x.x.x:8808/quick/Marshal.4.8/annotate-2.4.1.beta1.gemspec.rz
--2014-02-07 14:53:12-- http://x.x.x.x:8808/quick/Marshal.4.8/annotate-2.4.1.beta1.gemspec.rz
Connecting to x.x.x.x:8808... connected.
HTTP request sent, awaiting response... 404 Not Found
2014-02-07 14:53:12 ERROR 404: Not Found.
# wget http://rubygems.org/quick/Marshal.4.8/annotate-2.4.1.beta1.gemspec.rz
--2014-02-07 14:54:20-- http://rubygems.org/quick/Marshal.4.8/annotate-2.4.1.beta1.gemspec.rz
Location: http://production.cf.rubygems.org/quick/Marshal.4.8/annotate-2.4.1.beta1.gemspec.rz [following]
--2014-02-07 14:54:20-- http://production.cf.rubygems.org/quick/Marshal.4.8/annotate-2.4.1.beta1.gemspec.rz
Length: 471 [binary/octet-stream]
Saving to: “annotate-2.4.1.beta1.gemspec.rz”
2014-02-07 14:54:21 (48.0 MB/s) - “annotate-2.4.1.beta1.gemspec.rz” saved [471/471]

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

Nokogiri not reading/parsing structure of HTML file in CentOS

I've written a script to parse out some needed code in HTML files that are uploaded to our app. On OS X, this process works fine. However, when I upload to our testing server, it doesn't. When I go into the console on the test server and attempt to parse the file, Nokogiri won't see the structure - each time I get a single line of output instead of the whole document structure. The rest of my script isn't being executed because Nokogiri isn't traversing the document. Looking for some help on how to resolve the issue.
Here's the requisite code I'm using to open the file and feed it to Nokogiri:
html = Nokogiri::HTML(File.open("index.html", "r"))
Here's what html equates to:
#<Nokogiri::HTML::Document:0x10d9bbf0 name="document" children=[#<Nokogiri::XML::DTD:0x10d9b81c name="html">]>
In OS X, I get the entire tree, as expected.
Here's the contents of index.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="stylesheet" href="zero.css" type="text/css" charset="utf-8" />
</head>
<body class="fullpage-vert" onunload="javascript:clearInterval(audioLoop);">
<div id="container">
<div id="danceHolder">
<img id="danceVid" src="1-1.jpg" width="320" height="480" alt="" />
</div>
<div id="introHolder">
<img id="introVid" src="0-1.jpg" width="320" height="480" alt="" />
<div id="ctabg"></div>
<div id="cta1"></div>
<div id="cta2"></div>
<div id="cta3"></div>
<div id="phone"></div>
<div id="logo"></div>
</div>
</div>
bridge test
<frameset cols="25%,75%">
<frame src="frame_a.htm" />
<frame src="frame_b.htm" />
</frameset>
</body>
</html>
When I try and search for the frameset, for example, I get nothing:
html.css("frameset").size
0
I know Nokogiri has problems with the default Libxml2 version installed on CentOS (2.6.2), but I've followed the instructions to get it built on a new version (2.7.8). Here's the output for nokogiri -v:
# Nokogiri (1.5.0)
---
warnings: []
nokogiri: 1.5.0
ruby:
version: 1.9.2
platform: x86_64-linux
description: ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]
engine: ruby
libxml:
binding: extension
compiled: 2.7.8
loaded: 2.7.8
Has anyone else seen behavior like this?
For some reason, swapping
html = Nokogiri::HTML(File.open("index.html", "r"))
for
html = Nokogiri::HTML(File.read("index.html"))
works, although now it won't calculate line numbers properly (everything is line number 0).

Resources