Reputation: 4940
In my rails app, I'm trying to show all the users who liked a post in a twitter tooltip (sort of like facebook i guess).
The ruby code to get all of the users is
<% product_feed_item.voters_who_voted.each do |voter| %>
<%= voter.full_name %>
<% end %>
And Here is my tooltip code
<%= link_to likes_path(product_feed_item.collection, product_feed_item), class: "tooltip", :title => "", :"data-toggle" => "tooltip", :"data-placement" => "top", :'data-original-title' => " (NEEDS RUBY CODE FROM ABOVE" do %>
Link
<% end %>
I just don't know the proper way to put that block of ruby code inside of the data-original-title part of the tooltip. If anyone can help me out it's greatly appreciate. I think I provided all of the code you should need but if I can provide any more please let me know.
Thanks in advance. Happy Holidays and War Eagle!
Upvotes: 1
Views: 204
Reputation: 22899
To achieve exactly what you've asked for, try this:
<%= link_to likes_path(product_feed_item.collection, product_feed_item), class: "tooltip", :title => "", :"data-toggle" => "tooltip", :"data-placement" => "top", :'data-original-title' => product_feed_item.voters_who_voted.map(&:full_name).to_sentence do %>
Link
<% end %>
Or to be more idiomatic, create a helper that returns a humanized list of voters' names.
Upvotes: 1
Reputation: 176472
<%= link_to likes_path(product_feed_item.collection, product_feed_item), class: "tooltip", :title => "", :"data-toggle" => "tooltip", :"data-placement" => "top", :'data-original-title' => product_feed_item.voters_who_voted.map(&:full_name).to_sencence do %>
Link
<% end %>
However, it's definitely a bad practice to write all that Ruby code in a view and definitely a bad practice to chain all such Ruby methods altogether.
I encourage you to refactor the code using Helpers and/or write some custom method in the ProductFeeditem class such as ProductFeeditem.voters_names
.
Upvotes: 1