Passing param values to redirect_to as querystring in rails

后端 未结 2 962
梦如初夏
梦如初夏 2021-01-31 17:16

This should be simple, but I can\'t seem to find an easy answer.

How can I pass param values from the current request into a redirect_to call? I have some form values I

2条回答
  •  暖寄归人
    2021-01-31 17:45

    The 'Record' form of redirect_to uses the second argument only for the response status. You'll have to use another form of redirect_to, like the 'String' form. e.g.:

    redirect_to thing_path(@thing, :foo => params[:foo])
    

    which will work for nested params[:foo] params like you mentioned. Or, as Drew commented below, you can use polymorphic_url (or _path):

    redirect_to polymorphic_path(@thing, :foo => params[:foo])
    

提交回复
热议问题