Unwanted characters in cached pages - Rails 5 - ruby-on-rails

I'm exploring the Rails caching in order to speedup the page loading of a website that is becoming very big passing the time.
Said this i'am done the simple steps to enable caching on my pages and it works very well.
Using caches_page :page_name
I have only one issue - I find a lot of unwanted characters in my page, it is regarding letters like "à" or " ' ", " ° ".
E.g. : instead of "'" i got "’"
this is related both for text inside the database and static text in the page.
What should be the cause of this wrong font rendering?
My fonts are included in the fonts directory and work very well in the non cached pages - they are google fonts (Roboto and RobotoCondensed).
I'm using heroku for production and I don't know if I have to change some production environment configuration to manage this.
I got no errors in console and no other messages.

SOLVED!
there was a missing line in my of the html layout file:
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
this set the correct character encode on all the pages

Related

Strange whitespace appearing in MVC4 Razor View

I'm developing an app in ASP.Net MVC4 and am having a strange issue with whitespace. I've developed plenty of MVC3 sites with Razor without this issue.
Here's my template cshtml file:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>HF - Content Management - #ViewBag.Title</title>
<link href="#Url.Content("~/content/bootstrap/bootstrap.min.css")" rel="stylesheet" />
#Styles.Render("~/bundles/css/hf-cms-logged-in")
</head>
<body>
#Html.Partial("Partials/NavBar")
<div class="container">#RenderBody()</div>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="#Url.Content("~/scripts/bootstrap/bootstrap.min.js")"></script>
#Scripts.Render("~/bundles/js/validation")
<script src="#Url.Content("~/scripts/hf-cms.js")"></script>
</body>
</html>
Note the line with the RenderBody() call - there's no extraneous whitespace here.
When I call an action, the rendered body is prepended with some whitespace which I can't see that I've added, and can't seem to get rid of. I call an action with no logic, it only returns the following view:
#{
ViewBag.Title = "Dashboard";
}
<h1>Dashboard</h1>
It's definitely using the correct template (specified in my _ViewStart.cshtml)
Viewing the page in Google Chrome, the source shows extra whitespace. See the image below:
A similar issue can be seen in IE10. This is obviously affecting the design. I've tried using Meleze.Web to strip out any extra whitespace, but whitespace still remains.
I'm at a loss with this one, as it's a relatively simple site so far, there's nothing funky going on yet, so I can't see where this whitespace is coming from.
Has anybody else seen this with MVC4 or Razor before?
Edit: I've tried removing all stylesheets and script files, the whitespace still exists.
After struggling with this for a while, I've found the solution.
There must have been a funny character in the root _ViewStart.cshtml file. I deleted the contents of the ViewStart file and retyped it, which solved the problem. This got me thinking that a strange character could be causing the issue.
Don't like answering my own question, but I hope this helps somebody else. In theory, this won't be an MVC4-specific issue, you could encounter the same problem in MVC3.
I encountered the same problem, and Steve's answer put me on the right track, that it might be an unusual character embedded in the file.
In my case, it turned out to be a duplicate Unicode Byte-Order Mark (0xEFBBBF) at the start of the file. It seems to have snuck in when I copied and pasted the file contents in from a Git Extensions diff view.
Incidentally, Visual Studio has a built-in Hex viewer. If you right-click on a file in the Solution Explorer and click "Open With..." you can select "Binary Editor".
I have been experiencing the same problem, and tried the approach you put forth, Steve. However, that didn't solve my problem. What I found was involved in causing the problem was the h2 tag at the top of my child page:
<h2>#ViewData("Title")</h2>
When I removed the wrapping tags, everything worked fine:
#ViewData
As a test, I took the styles for the h2 and placed them in their own class and then wrapped my page title content with a span:
<span class="pagetitle">#ViewData("Title")</span>
This worked fine, so is how I corrected the problem with my site. Though I don't know the true root cause, this did fix my problem, so perhaps it will help someone else out there.
I've just experienced a similar problem - in my case, one of the #using directives at the top of the view was causing an issue. I found the same thing in a couple of different views in my project.
One thing that helped me to locate the offending characters was pasting the whole view's contents into Notepad - it was immediately clear that the lines in question had somehow been encoded differently (they appeared smaller than the other lines, even in Notepad). Deleting the lines and rewriting them from scratch solved the issue, though I'm sadly none the wiser how I got into that position in the first place...
I have had the same issue and thanks to the clues here I was able to identify the problem.
After a lot of investigation I figured out that there was a Unicode character ‘zero width no-break space’ at the start of the page. This character is added to a page when it is saved/encoded as ‘UTF-8 with BOM’. I can only guess that the page was edited outside of visual studio, copied in from somewhere else, or maybe the page encoding was set incorrectly in VS. You stated in other answers you can see it by the looking at the once copied and pasted into notepad.
I faced the same problem, and I fixed it as follwoing:
- change column (Field) datatype in your database from nchar to nvarchar.
this is because nchar reserve fixed length, hence if your string is shorter than this length it will complete it with spaces.
I had a similar problem, but a much more obvious solution. I had an Html.Partial() inclusion in my <head> element with an ; after the method call. Which again is rendered in the body.
<head>
#await Html.PartialAsync("Test"); // The ";" is rendered in the body, remove it!
</head>
<body>
...
</body>

character set encoding issue with multi-language featured site

I am here suffering from a simple, common problem.
my site is multi-language featured, built in codeigniter framework.
for eg for a french language here i have used
$lang['login'] = 'ConnÈcter';
this then appeared as Conn�cter in the view.
then i solved this by adding
<meta charset="ISO-8859-1">
which then resolved the issue.
but when the contents is loaded with characters like
Sáenz-Mata & Jiménez-Bremont
then is is changed to
Sáenz-Mata & Jiménez-Bremont
note é is changed to é even when i use
<meta charset="ISO-8859-1">
when above meta is removed, it gives me Conn�cter when the language is converted to french.
so please suggest me something which can handle both situations.
hope somebody understands it.(got messed up describing.)
thanks.
use <meta charset="utf-8">
Use UTF-8 consistently for all pages, as explained in the CodeIgniter User guide. Make sure the encoding of each file matches its declared encoding. What you are experiencing now is caused by mixing encodings (UTF-8 and ISO-8859-1 mostly).

ASP MVC 3, UTF-8 HTML charset not showing Polish chars. (Razor)

As title says. Story is, I've changed meta mark-up of my _Layout.cshtml page from:
<meta charset="utf-8" />
to
<meta content="text/html; charset=utf-8">
Effect? No Polish characters on page. Ok, let's revert the change. Effect? No Polish characters on page.
Btw it affects ONLY _Layout.cshtml, all other views show Polish letters properly. Proper letters are replaced by "Ĺ‚" characters.
Any ideas? Thought about changing browser, but it didn't work. Same stuff happens on different computer.
No other changes were made. Tried to revert project to older version from repository, didn't work.
Opened in notebook and saved again wit UTF-8 encoding set. Worked.

strange UTF-8 byte encoding issue with Rails, IE, PostgreSQL, delayed_job

I'm seeing a relatively strange (and hard to diagnose) error with a combination of IE8, Rails 3.0.3, PostgreSQL and delayed_job.
I have a text area on one of my pages, and in the controller I delay a message with delayed_job which includes an object which has the content from the text area:
SomeMailer.delay.send_message(message)
This works fine on Chrome, FF, Safari. However in IE8 only, and only when I actually enter text in the text area, and it looks like only when I enter a carriage return in the text area (I think), I get this error from the controller:
invalid byte sequence in UTF-8
This appears to me to be when delayed_job is serializing the job to the database via ActiveRecord, that it doesn't like the character encoding in the newline (\r\n). It's a bit hard to figure out because I don't know if this is an IE, Rails, delayed_job or Postgres issue.
Side Note: I'm getting this error locally, but it doesn't appear that this error appears on Heroku - so maybe they have their database configured better than I do?
Environment:
Rails 3.0.3
Ruby 1.9.2
Postgres 8.4 - encoding UTF8, collation en_US.UTF-8
delayed_job 2.1.4
IE 8
Any thoughts would be appreciated.
Are you setting your encoding in the HTML that is being sent to IE8? e.g.:
<!doctype html>
<head>
<meta charset="utf-8">
</head>
It's possible that the other browsers are working around the missing information and assuming UTF-8 when encoding the data from your text area.

Anyone have good complete examples of using sitemesh and layouts in Grails 1.2?

I had a grails 1.1 app working where keyword and description meta tags were dynamically generated. There was a change in how that works in 1.2, but I cannot found good documentation. I've tried numerous ways to make it work. No matter what I do the resultant html gets something like
<meta name="keywords"/>" />
instead of the actual keywords. The extra tags there are not a typo on my part. So it also creates a bug in my rendered html.
In Grails 1.2, there's a performance optimized integration to Sitemesh. You can use the old implementation if you specify grails.views.gsp.sitemesh.preprocess = false in Config.groovy.
There are several issues in Grails JIRA related to meta tags :
http://jira.codehaus.org/browse/GRAILS-5605
http://jira.codehaus.org/browse/GRAILS-5598
http://jira.codehaus.org/browse/GRAILS-5696
Some of them will be fixed in Grails 1.2.1 .
I have had problems in 1.2 with meta tags dynamically generates and found that the problems happened when the quote was followed by a $. If I put a space between the quote and the $ it worked like
<meta name="keywords" value=" ${keywords}"/>
May or may not be your problem...

Resources