Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Nesting text within a content tag.
# The HTML that should be generated is:
# <h3 class="curated_by">Curated by <span>Bob</span></h3>
# Please tell me that there's a better way to do this.
def curated_by
html = ''
html += h.content_tag(:h3, :class => 'curated_by') do
h.concat h.t('phrases.Curated_by')
h.concat ' '
h.concat h.content_tag(:span, curator_username)
end.html_safe
html.html_safe
end
@victorbstan
Copy link

def curated_by
  "<h3 class='curated_by'>#{t('phrases.Curated_by')} <span>#{curator_username}</span></h3>"
end

Note, you're not nesting text in a content_tag, but why do you need to nest text necessarily?

@nickhoffman
Copy link
Author

@victorbstan I considered that, but writing raw HTML feels so wrong, even in a presenter.

@victorbstan
Copy link

The ideology of perfection is crippling though, isn't it?

@nickhoffman
Copy link
Author

Hah yeah, it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment