Rails 3.1 link_to weird issue - ruby-on-rails

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%;
}

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

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

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.

Bootstrap 'small' tag not playing nicely with link_to rails helpers

I'm having an issue getting the '-' (dash) to be directly in front of the link that uses "#natelie_h" as the anchor text. It breaks it on to the next link for some reason.
<div class="span3">
<blockquote><p>"My favourite part of the service is the information pack that comes with the flies"</p><p><small><%= link_to "#natelie_h", "https://twitter.com/natelie_h", :target => "_blank" %> </small></p></blockquote>
</div>
Here you can see what I mean: http://www.clockworkflies.com/ (customer quotes, near the bottom).
That is because and in have a display:block, and "-" is added before but "-" is inline, so is shown on new line
Try
blockquote small a:before {
content: "— ";
}
in css, instead of "blockquote small:before"
Another option is to set not display:block but display:inline-block for blockquote small and blockquote small a. But IE6 and IE7 does not support this css variable

Rails tutorial, odd CSS formatting on site

You can see it here.
The site looks fine when I remove Blueprint. I've tried adding Bootstrap and the same issue occurs.
I've been following this (excellent) tutorial.
According to chrome, this is the code causing this:
http://blazing-fog-1717.herokuapp.com/assets/application-fcc74be8bd91511db934f033390efd28.css
a:link::after, a:visited::after {
content: " (" attr(href) ")";
[...]
I have no idea why blueprint might be doing this, but you can just edit blueprint.css and remove the following rule:
content: " (" attr(href) ")";
Setting the media attribute of your links to print (media="print") can fix the problem as well.
If you don't like either of these solution, you should be able to over-write the css by adding the following CSS code AFTER the inclusion blueprint:
a:link:after, a:visited:after {
font-size:90%;
content: none;
}
I'm not sure about that last part, but you could try it out.
I had the same problem, try to add the following line to config/environments/production.rb
config.assets.precompile += [ "blueprint/*.css" ]
This step is described in section 5.4.3 Deploying to production with Blueprint ;)

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