Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8359341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:06:56+00:00 2026-06-09T11:06:56+00:00

I have an article, and each article has tags. Right now I call all

  • 0

I have an article, and each article has tags. Right now I call all the tags together:

<% @articles.each do |article| %>
  <div class="articlebox">
    <article>
      <h4>
        <%= link_to article.title, article_path(article) %>
      </h4>
        <%= markdown article.body %>
      <span class="articletagbox">  
        <%= article.tag_tokens %>
      </span>   
<% end %>

Right now my class goes around all the article tags. I want it to go around each article tag individually.

I’ve tried a simple

<% @tags.each do |tag| %>

but that gives me an undefined method “each” nilclass error.

I know this is pretty simple, but I just can’t figure out what I’m supposed to change to make it work. I assume I need to define something in my article model?

Thanks!

EDIT

So right now my code looks like this:

<% article.tags.each do |tag| %>
  <span class="articletagbox">  
    <%= article.tag_tokens %>
  </span>   
<% end %>   

and the method in article.rb is:

def tag_tokens
  self.tags.collect{|t| t.name}.join(", ")
end

which is returning all the tags associated with each article the same number of times as there are tags.

So for example, if I have three tags on an article: tag1, tag2, tag3 I get

<class>tag1 tag2 tag3</class> <class>tag1 tag2 tag3</class> <class>tag1 tag2 tag3</class>

Instead I want

<class>tag1</class> <class>tag2</class> <class>tag3</class>

So I’m just not sure why I’m getting all the tags associated with each article returned together, but the same number of times as there are tags. I hope that makes sense.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:06:59+00:00Added an answer on June 9, 2026 at 11:06 am

    If one article has many :tags then in the article loop do

    <% article.tags.each do |tag| %>
    

    Following your edit : you’re outputting a method called on the article while looping on tags. Doesn’t make sense, you’re looping on tags, call tag.name instead!

    Check slhck answer for the specific syntax

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of articles, and each article has its own title and
So I have a blog: www.elnacional.com.uy Each article has it's open graph meta tags,
i have a list of articles, and each article has one or more votes
I have an HTML 5 page with several articles. Each article has a custom
Say that I have an article with multiple pages. Each page has a short
i have a website which contains many news articles. IN the database, each article
I have a website with 3 pages, while each page has articles that are
Have an article model, each article has an author and publisher (both are tables).
I have two tables. One of events and one of articles. Each event has
I have a table: <table class=articles> <%= render :partial => 'articles/article' , :collection =>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.