Theopap
Theopap

Reputation: 755

Ruby on Rails link_to URL and add the id at the end

I'm trying to link_to a url and would like to add the id at the end. The id is in a global variable @id:

<%= link_to "link", "https://www.example.com/sample-#{@id}" %>

The above returns this:

https://www.example.com/sample-#%3CItem:0x007fe66cf8e850%3E

Any idea how I can implement this?

Upvotes: 1

Views: 158

Answers (1)

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230286

how can I implement this?

Exactly like you did. Only make sure that @id contains an actual id (simple value) and not a complex object Item. Or rename it to @item.

If you're in a hurry, this is the lazy change:

<%= link_to "link", "https://www.example.com/sample-#{@id.id}" %>

Upvotes: 5

Related Questions