Send querystring params as part of form post

前端 未结 4 1766
青春惊慌失措
青春惊慌失措 2021-02-08 17:40

Is there a way to capture the querystring and send that along as part of a form post? I\'m using Rails 2.3.5 and my user is on a page that has multiple querystring parameters. O

相关标签:
4条回答
  • 2021-02-08 17:50
    <% form_tag params.merge(:action=>"someAction") do %>
    

    - No route matches [POST]

    0 讨论(0)
  • 2021-02-08 18:00

    The preferred way would be to use hidden fields. I haven't tried it, but I think you can specify additional query string parameters within the *_path or *_url helpers. Something like:

    <% form_for(@post,
               :url => post_path(@post, :foo => 'foo', :bar => 'bar')) do |f| %>
      ...
    <% end %>
    
    0 讨论(0)
  • 2021-02-08 18:01

    A friend of mine showed me what I believe is an easier way:

    <% form_tag params.merge(:action=>"someAction") do %>
    

    Merging params into the hash necessary for making the form_tag did the trick perfectly.

    0 讨论(0)
  • 2021-02-08 18:10

    Use hidden_field_tag if you're using a GET request.

    In our case we were using a simple form with a select for setting the Per Page values for pagination. We found that any existing GET params were cleared when submitting this form. To fix this we used hidden_field_tags in our form.

    Inside of your form, just set hidden_field_tags for the existing GET params, like so:

    form_content = request.query_parameters.collect do |key, value|
      hidden_field_tag key, value
    end
    

    This will ensure that your existing params persist.

    0 讨论(0)
提交回复
热议问题