简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM