Beetlejuice
Beetlejuice

Reputation: 4425

Rails helpers without @template.content_tag

there are another ways to create helpers instead of using @template.content_tag and @template.concat commands?

These look too verbose.

Actually I need to rewrite some helpers like text_field, radio_button, submit, etc..

Upvotes: 3

Views: 153

Answers (1)

GSP
GSP

Reputation: 3789

You want to generate HTML from your helpers, I assume?

You can simply generate strings using any method you want. If you call html_safe that will prevent the special characters from being escaped.

def header_helper
  '<div class="header">This is a test</div>'.html_safe
end

And in the template

<%= header_helper %>
<p>This is the content of the section</p>

Upvotes: 1

Related Questions