GVS GVS - 1 year ago 61
Ruby Question

link_to many tags instead of a single string

I am building a list of user notifications. When the current user clicks an

tag, which contains the entire notification content, they should be redirected to the mentioned post or user etc.

Here is what I am trying right now and can't seem to get it to work.

<%= link_to activity.activable do %>
<span><%= link_to(image_tag(activity.actor.avatar.url(:thumb)), user_path(activity.actor.username)) %></span>
<span class="us-rt-sg">
<%= link_to activity.actor.name, user_path(activity.actor.username), class: "us-rt-usnm" %>
<%= activity.action %> on
<%= link_to personalize_owner(activity, recepient), user_path(activity.activable.user.username) %>
<%= link_to 'Post', activity.activable %>
<span class="us-rt-sg-date"><%= time_ago_in_words(activity.created_at) %></span>
<% end %>

Once I get this to work, I will remove the line
<%= link_to 'Post', activity.activable %>
, because the entire
will be a link when clicked.

I also tried this on my activities main view page.

<li class="activity">
<%= link_to activity.activable do %>
<%= render "activities/#{activity.action}", activity: activity, recepient: recepient %>
<% end %>

Can someone show me what I need to do? Because so far everyhing I've done has not worked.

Answer Source

The wrapping link_to and the internal links are going to give you a headache. You have to decide what's most important in the element.

On the face of it, where you have a notification that should be clickable and link to the specified activity, you should remove the internal links and just link the whole content to the activity. Once they arrive at the activity, then you can include links to author, owner, and so on without worrying about a wrapping link.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download