I have a Rails 4 project where I'm trying to display relevant information about the host of an event. I'm writing in Haml instead of ERB.
I want to render a string describing the type of information about the host, followed by the information. For example:
Email: abc@123.com
I was able to get the mail_to working properly with the following line, although I had to use .html_safe to achieve that. I've heard that is bad practice. Can anybody confirm that?
%p= "Email: #{mail_to @host.email}".html_safe
Now I'm trying to do something similar with a link_to for the host's facebook profile. The desired result is similar to the email. For example:
Facebook Profile: www.facebook.com/somebody
But I have been having trouble with this one, and after an hour of searching, I wasn't able to find a definitive solution.
I was able to get it working by splitting it into two lines.
%p Facebook Profile:
= link_to @host.facebook_profile, "http://#{@host.facebook_profile}"
But that displays the link on the following line. I tried to use the same format as the email example, but that didn't work.
%p= "Facebook Profile: #{link_to @host.facebook_profile, @host.facebook_profile}".html_safe
When I do that, it appends the facebook_profile url to the end of the current route.
http://localhost:3000/venues/facebook.com/somebody
Any help would be greatly appreciated.
How about this?
%p= "Facebook Profile: #{link_to @host.facebook_profile, "http://" + @host.facebook_profile}".html_safe
Concatenate @host.facebook_profile
with http://
prefix so it becomes fully qualified url.