Skip to content

Instantly share code, notes, and snippets.

@between40and2
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save between40and2/b573858bc4f47f4d7e38 to your computer and use it in GitHub Desktop.
Save between40and2/b573858bc4f47f4d7e38 to your computer and use it in GitHub Desktop.
Comparing FormTagHelper, FormHelper, FormBuilder

ActionView::Helpers::FormTagHelper

def hidden_field_tag(name, value = nil, options = {})
    text_field_tag(name, value, options.stringify_keys.update("type" => "hidden"))
end

def text_field_tag(name, value = nil, options = {})
    tag :input, { "type" => "text", "name" => name, "id" => sanitize_to_id(name), "value" => value }.update(options.stringify_keys)
end

Output

<input id="tags_list" name="tags_list" type="hidden" />

ActionView::Helpers::FormHelper

def hidden_field(object_name, method, options = {})
    Tags::HiddenField.new(object_name, method, self, options).render
end

Output:

<input type="hidden" id="post_tag_list" name="post[tag_list]" value="#{@post.tag_list}" />

ActionView::Helpers::FormBuilder

def hidden_field(method, options = {})
  @emitted_hidden_id = true if method == :id
  @template.hidden_field(@object_name, method, objectify_options(options))
end

FormTagHelper

select_tag(name, option_tags = nil, options = {})

FormOptionsHelper

select(object, method, choices = nil, options = {}, html_options = {}, &block)

FormBuilder

select(method, choices = nil, options = {}, html_options = {}, &block)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment