watt
watt

Reputation: 879

How can I have both text and a variable in link_to text?

I'd like to have something like this as output:

<a href="...">See Los Angeles</a> or

<a href="...">See New York</a> etc, so New York and Los Angeles would be a variable.

How can I achieve that with Rails? I read something and tried this, but it didn't work:

<%= link_to 'See #{@city.name}', @city  %>

Thanks!

Upvotes: 0

Views: 1190

Answers (1)

watt
watt

Reputation: 879

Nevermind, the above solution works but I had to put double quotes, not single. So this is the solution:

<%= link_to "See #{@city.name}", @city  %>

Upvotes: 2

Related Questions