Question

The following statement...

content_tag(:li, concept.title)

...returns something like:

<li>"My big idea"</li>

The following method definition, when called, returns the same:

def list_of_concepts(part)
 content_tag(:li, concept.title)
end 

As does...

def list_of_concepts(part)
 content_tag(:li, part.concepts.first.title)
end  

But the following...

def list_of_concepts(part)
  for concept in part.concepts
    content_tag(:li, concept.title)
  end
end  

...just gives me a bunch of pound signs ("#") in my view, like it's returning true or false or a count rather than whatever content_tag returns. How can I make it return what content_tag returns?

Thanks again,

Steven.

Was it helpful?

Solution

the for loop doesn't return your data, try this:

def list_of_concepts(part)
  part.concepts.map { |c| content_tag(:li, c.title) }.join
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top