Jadam
Jadam

Reputation: 1775

link to Twitter profile with only a Twitter name - RoR

I have user's Twitter names and want to add links from their profiles to their Twitter accounts.

I've been trying to concatenate @Profiles.twitter (their twitter name) to the end of a plain twitter.com hyperlink, but with no luck.

Currently I have it just showing the names in text, but want them to be links

<p>
  <strong>Twitter:</strong>
  <%= @profile.twitter %>
</p>

you can view the result here: http://warm-hollows-1154.herokuapp.com/profiles/4

Upvotes: 1

Views: 184

Answers (1)

Pierre
Pierre

Reputation: 1114

Example:

<% @name = "pierre" %>
<%= link_to @name, "http://www.twitter.com/" + @name %>

Try this

<%= link_to "LINK", "http://www.twitter.com/" + @profile.twitter[1..-1] %>

Edit:

[1..-1] removes the @ sign

You don't need to create @name, i just used it as an example, you alreade have a string @profile.twitter. Just use this below

<%= link_to @profile.twitter, "http://www.twitter.com/" + @profile.twitter[1..-1] %>

Upvotes: 1

Related Questions