Rails: Hidden field in form_for is not sending parameters to controller

Andrej picture Andrej · Feb 1, 2011 · Viewed 15.4k times · Source

I have a form_for I'm making in my view helper that is going to let one user promote another user from a group.

  def promote_button_for(group, user)
    membership = group.get_membership( user )
    form_for membership, :url => group_membership_path( group, membership ) do |f|
      f.hidden_field :group_creator
      hidden_field_tag 'test', '1'
      f.submit( "Promote", :onclick => "return confirm(\"Are you sure you want to promote #{user.email} to an officer?\")" )
    end
  end

When I submit the form via the button, I don't seem to get any of the hidden field parameters sending to the controller.

Started POST "/groups/1/memberships/6" for 127.0.0.1 at 2011-02-01 01:45:32 -0600
  Processing by MembershipsController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"VQl/rVX8OVOETv2HE7KtopUc3B19ShoMkUhjJwNlaZs=", "commit"=>"Promote", "group_id"=>"1", "id"=>"6"}

The generated Html looks like:

<form accept-charset="UTF-8" action="/groups/1/memberships/6" class="edit_membership" id="edit_membership_6" method="post">
   <div style="margin:0;padding:0;display:inline">
      <input name="utf8" type="hidden" value="&#x2713;" />
      <input name="_method" type="hidden" value="put" />
      <input name="authenticity_token" type="hidden" value="VQl/rVX8OVOETv2HE7KtopUc3B19ShoMkUhjJwNlaZs=" />
   </div>
   <input id="membership_submit" name="commit" onclick="return confirm(&quot;Are you sure you want to promote [email protected] to an officer?&quot;)" type="submit" value="Promote" />
</form>

Any help would be greatly appreciated,

Thanks!

Answer

crazycrv picture crazycrv · Feb 1, 2011

Can you try

f.hidden_field :group_creator, {:value => ''}