Reputation: 2527
In my project I am using HAML. I use a construct similar to the following fragment throughout my project:
%a.social.twitter{:href => '...'}
%span.text Twitter
%span.twitter-icon
I want to write a helper to generate this fragment for me:
def social_network(name)
link_to(...) do
# generate span.text and span.twitter.icon
end
end
Ideally I don't want to just pass in some HTML disguised in string form to the link_to
block. I prefer to use a markup builder or an API.
What built-in options does Rails have that can be used for this purpose?
Upvotes: 0
Views: 78
Reputation: 35370
Rails has content_tag
and tag
in ActionView::Helpers::TagHelper
which
Provides methods to generate HTML tags programmatically when you can’t use a Builder.
For example:
def social_network(name, klass)
link_to(...) do
content_tag(:span, name)
tag(:span, class: klass)
end
end
Upvotes: 1