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

佐手、 提交于 2019-12-05 03:22:33

You are having this problem because the form_for object is only seeing the string that is generated by the last f.submit tag, while everything else between the form_for and the f.submit is lost.

In this case, the form_for tag does not manipulate the view directly, as it is basically just a string that is returned from the promote_button_for method.

The answer is that you just need to chain the generated tags together, like this:

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

Notice the << \, which concatenates all the generated strings together and returns them to form_for.

Can you try

f.hidden_field :group_creator, {:value => ''}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!