Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Looping has many relation with <i> tags #686

Closed
maier-stefan opened this issue Jul 10, 2015 · 1 comment
Closed

Looping has many relation with <i> tags #686

maier-stefan opened this issue Jul 10, 2015 · 1 comment

Comments

@maier-stefan
Copy link

Is it possible to loop over multiple i tags?
my model has a has_many relation with Geography so i want to display the flags in the frontend.
So the question is where and how should i do the loop?

def geo_to_flags
    h.content_tag :span, title: geographies.map(&:code).join("|") do
      geographies.each do |geo|
       h.content_tag(:i, class: "famfamfam-flag-#{geo.code}") do
       end
      end.joins
    end
  end

this is not working

Or is this approach completely wrong?

@codebycliff
Copy link
Collaborator

This doesn't have anything to do with Draper, but instead with how to write helpers. Something like this should work though:

def geo_to_flags
  h.content_tag :span, title: geographies.map(&:code).join('|') do
    geographies.each do |geo|
      h.concat h.content_tag(:i, nil, class: "famfamfam-flag-#{geo.code}")
    end
  end
end

There may be a better way to accomplish this, but that will do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants