Rails: = provide(:title, t('.title')) fails if there is a single quote - ruby-on-rails

I can't figure out how to fix a problem with a title translation that contains a single quote. More of that it happens only when calling
= provide(:title, t('.title'))
When referencing the same YAML translation as H2, it is displayed correctly:
.row
h2 = t('.title')
Here is a line of YAML translation line:
home:
faq:
title: FAQ
about:
title: "À propos d\'Entreprise"
The title is displayed as follows
À propos d'Entreprise
Any idea about how to solve that ? Thank you.
OS: OS X
Rails 4.2.5
Ruby 2.3.0
YAML

Found out how to fix that. I think it is due to the way that Slim interprets code snippets
So here is what I had in application.tml.slim:
title =full_title(yield(:title))
The working version is:
title ==full_title(yield(:title))
Hope this helps.

Related

Capybara::Poltergeist::MouseEventFailed after Haml update (4.0.7 => 5.0.2) [RAILS]

Hi we are currently updating our HAML file from version 4.0.7 to 5.0.2. After the update a lot of cucumber tests break saying;
Firing a click at co-ordinates [422.5, 414] failed.
Poltergeist detected another element with CSS selector 'html.javascript body div.ui-widget-overlay.ui-front' at this position.
It may be overlapping the element you are trying to interact with.
If you don't care about overlapping elements, try using node.trigger('click').
(Capybara::Poltergeist::MouseEventFailed)
It breaks at the parts where i'm using interpolation in i18n texts like this:
You_are_on_a_device: You are on a %{type} device
And in the view im using something like this:
%p.dialog{'data-attribute' => t('you_are_on_a_device', type: 'small').html_safe, hidden: true}
I can't seem to find the breaking change from the Haml Changelog
Does anybody know whats causing this and what i can do to fix this?
Solved:
The solution was to put the data attributes value in an interpolated string like this:
%p.dialog{'data-attribute' => "#{t('you_are_on_a_device', type: 'small').html_safe}", hidden: true}
and in my config/initializers/haml.rb
Haml::Template.options[:escape_html] = false
It was because of the html escaping that has become standard in HAML 5.0.0, where it wasn't in HAML 4.0.7
Disabling html escaping is NOT a good practice because it makes your app prone to XSS attacks. For example, when an attacker type in their username <script>alert('Vasya')</script> other users will see an alert every time Vasya's name will appear on the page. Try the following code:
%p= "<script>alert('Vasya')</script>"
I installed haml 5.0.2 in a fresh rails project (rails 4.2.6) and I tried to render the following page:
%h1 HAML
%p.dialog{'data-attribute' => t('you_are_on_a_device', type: 'small').html_safe, hidden: true}
%p.dialog{'data-attribute' => "#{t('you_are_on_a_device', type: 'small').html_safe}", hidden: true}
I don't see any differences in the rendered p tags (I've tried both escape_html true and false):
<h1>HAML</h1>
<p class="dialog" data-attribute="You are on a <a href="http://mywebsite.nl/type">small</a> device" hidden=""></p>
<p class="dialog" data-attribute="You are on a <a href="http://mywebsite.nl/type">small</a> device" hidden=""></p>
I guess that the Failed to click on element issue is caused by other reason, maybe you upgraded capybara or capybara-related gem while upgrading haml
Also it is a good practice to render data-attributes using hash notation:
%p.dialog{data: { attribute: t('you_are_on_a_device', type: 'small').html_safe }, hidden: true}
See more detailed documentation on the haml data attributes here

Syntax highlighting issue on multiline code in Sublime Text 3 (Ruby on Rails & Haml)

Syntax highlighting in my html.haml view fails when I break up my code on several lines:
Example:
Syntax highlighting working on single line:
= link_to results_path(keyword), remote: true, rel: 'tooltip', title: 'Voir les résultats Google' do
%i.icon-external-link
But on multiple lines, syntax highlighting only works on the first one:
= link_to results_path(keyword), remote: true,
rel: 'tooltip', title: 'Voir les résultats Google' do
%i.icon-external-link
what I get: no syntax highlighting on "child" lines
what I would expect: syntax highlighting even on child lines
Here are the packages I have installed referring to syntax highlighting & code display:
ApplySyntax
Haml
+Ruby on Rails snippets
This https://github.com/iRet/sublime-haml fixes the issue for me (Sublime 3). After installation, just select Ruby Haml (the root list with syntax options) instead of Rails -> Ruby Haml.

Inline Attachment image is not displaying in Rails 4

I've been trying to show inline attachments in my mail (logo),
I've seen many answers on the community, nothing seems to be working for me,
Mail is going fine,I can see the text but unable to see image
this is my mailer:
path variable contains path to logo
attachments.inline['logo.png'] = { content: File.read(path),mime_type: "image/png" }
this is my view:
Welcome to my site
<%= image_tag attachments['logo.png'].url%>
Please Help,I've been pulling my hair for hours now on this.
In your mailer try:
attachments.inline["myimage.png"] = File.read(File.join(Rails.root, "app", "assets", "images", "myimage.png"))
your view code is correct.
I've been using this code successfully with one image, though there may be a bug in rails. Check: https://github.com/rails/rails/issues/2686

Rails 3.1 link_to weird issue

I am having hands on Rails 3.1 rc1. There is a weird issue keeps bothering me. Whenever I use link_to function, the link href also appearing.
For example:
<%= link_to 'Say Hello' , '/say/hello' %>
produces the below output in the browser
Say Hello (`/say/hello`)
I don't know why the link href also displaying this way.
I tried the below as well:
< a href="/say/hello"> Say Hello < /a>
Still the same output. It seems like the issue is not related to Rails ???
Please help. You advise is valuable.
Are you using blueprint? I was seeing the same issue, and it was due to blueprint's print.css:
a:link:after, a:visited:after {
content: " (" attr(href) ")";
font-size: 90%;
}

Ruby on Rails anchors/links during development problem

This may not be a big problem but I find this one as irritating. I wasn't able to figure it out. I have anchors in my site using link_to and even normal tags. Example:
Demo
will show up as Demo(#)
Authenticate would show up as Authenticate (/authenticate)
But if I view the source from the browser, I can't see a problem.
Does anybody know about this problem? I am using Rails 3 and a MAC.
Thank you,
Junrey
I finally found the answer to my problem and it has something to do with the Blueprint CSS Framework that I am using.
I need to remove this content: " (" attr(href) ") "; from print.css which shows something like this:
a:link:after, a:visited:after { content: " (" attr(href) ") "; font-size: 90%; }
Found the solution from Ruby-Forum (http://www.ruby-forum.com/topic/206645#935056).

Resources