1 Replies - 945 Views - Last Post: 03 October 2016 - 09:48 AM Rate Topic: -----

#1 tonyal  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 85
  • Joined: 23-September 14

Span on links from loop in Rails.

Posted 02 October 2016 - 05:32 PM

Hello. I'm new to Ruby on Rails and I'm trying to use a span on some links. The links are from tag names stored in a database that the blog writer picks for a post. I'm putting my putting my bootstrap html file into my ruby file and I'm stuck at this part. Here are the two codes.

Ruby code:
<% if Setting.tag_visible? %>
     <% post.tags.each do |tag| %>
          <%= link_to tag.name, posts_path(tag: tag.name) %>
     <% end %>
<% end %>



Html code:
<span class="label label-default">tag from db</span>



I tried:
<%= link_to(content_tag(:span, :class => 'label label-default')) tag.name, posts_path(tag: tag.name) %>


and also putting the content_tag section up after the post.tags.each but no joy. Most of the span examples or link_to with span examples don't use the post_path or aren't set up like mine. If anyone could shed some light, I'd be very grateful! Thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Span on links from loop in Rails.

#2 tonyal  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 85
  • Joined: 23-September 14

Re: Span on links from loop in Rails.

Posted 03 October 2016 - 09:48 AM

In case anyone with the same question finds this post - I figured it out.

<% post.tags.each do |tag| %>
     <%= link_to tag.name, posts_path(tag: tag.name), :class => 'label label-default' %>
<% end %>



I'm not sure if it's the best way to go about it, but for now it works. Cheers :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1