Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: link_to not rendering dynamic text

In my rails 4 erb view i have this link,

<%= link_to "Download @served_file.title", "/public/uploads/@served_file.file", :class => "btn" %>

However, it won't replace @served_object.title and @served_object.file with the text but just placing those lines inside a <%= %> works as expected.


1 Answers

You need to interpolate the values into the string.

<%= link_to "Download #{@served_file.title}", "/uploads/#{@served_file.file}", :class => "btn" %>
like image 53
Paritosh Piplewar Avatar answered Mar 13 '26 22:03

Paritosh Piplewar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!