Using Rails link_to for links that post

后端 未结 5 1063

I have a link that I need to submit a post request with. Normally, I\'d use jQuery and prevent the link\'s default behavior and then submit a form to the destination. This s

5条回答
  •  醉酒成梦
    2020-12-02 14:53

    You can encode parameters in the URL this way :

    link_to "Profile", 'http://example.com/profile?' + {param1: 'value1', param2: 'value2'}.to_param, method: :post
    

    If it does not fit your needs you are better use a form than a link_to.

提交回复
热议问题