Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Hidden data in form_for tag #7461

Closed
wants to merge 8 commits into from

1 participant

Egor Homakov
Egor Homakov

Before:

<%= form_tag({action: :authorize, controller: :charm}) do %>
<%=hidden_field_tag :client_id, @client.id %>
<%=hidden_field_tag :scope, @client.scope %>
...
<% end %>

now

<%= form_tag({action: :authorize_accept, controller: :charm}, hidden_data:{client_id: @client.id, scope: @client.scope}) do %>
...
<% end %>

Why adding it as parameter in form_for is a nice solution? because the only purpose of type=hidden is to add some parameters to request, only data payload and there is no difference where will you put this tag inside of form.
Also, we already have a <div style="margin:0;padding:0;display:inline"> to keep all our hidden datas there.

/cc @tenderlove @josevalim

Egor Homakov homakov closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 27, 2012
  1. Egor Homakov

    test

    homakov authored
  2. Egor Homakov

    hidden_data

    homakov authored
Commits on Aug 28, 2012
  1. Egor Homakov

    map

    homakov authored
  2. Egor Homakov

    Add hidden_data in form_for

    homakov authored
  3. Egor Homakov

    Add hidden_data in form_for

    homakov authored
  4. Egor Homakov
  5. Egor Homakov

    hidden_data in form_for

    homakov authored
  6. Egor Homakov

    hidden_data in form_for

    homakov authored
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 0 deletions.
  1. +7 −0 actionpack/lib/action_view/helpers/form_tag_helper.rb
7 actionpack/lib/action_view/helpers/form_tag_helper.rb
View
@@ -745,6 +745,13 @@ def extra_tags_for_form(html_options)
end
tags = utf8_enforcer_tag << method_tag
+
+ if hidden_data = html_options.delete("hidden_data")
+ hidden_data.map{|name, value|
+ tags << text_field_tag(name, value, {"type" => "hidden"})
+ }
+ end
+
content_tag(:div, tags, :style => 'margin:0;padding:0;display:inline')
end
Something went wrong with that request. Please try again.