开发者

Rails link_to only hyperlinking part of link

开发者 https://www.devze.com 2022-12-17 08:44 出处:网络
I have <%=link_to distance_of_time_in_words_to_now(post.created_at), post %> ago However I want to make \'ag开发者_运维知识库o\' show up in link as well. Now its something like \'20 minutes

I have

<%=link_to distance_of_time_in_words_to_now(post.created_at), post %> ago

However I want to make 'ag开发者_运维知识库o' show up in link as well. Now its something like '20 minutes ago,' which kind of looks ugly. I want it to look like 20 minutes ago.'

I tried using #{} with no success and Google search turns out very little, especially since I don't even know what I'm looking for.

Any suggestions?


This must work:

<%= link_to "#{distance_of_time_in_words_to_now(post.created_at)} ago", post %>

Don't know why it didn't work for you. Any code samples?


Try:

<%= link_to "#{distance_of_time_in_words_to_now(post.created_at)} ago", post %>


Also, the block syntax for long links:

<%= link_to post do %>
  <%= distance_of_time_in_words_to_now(post.created_at) %> ago
<% end %>

You could easily add an icon here, for example.

On a side note, it also doesn't add a horizontal scrollbar to StackOverflow's layout :)

0

精彩评论

暂无评论...
验证码 换一张
取 消