Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 5 redirect_back with url query parameter option

According to the docs:

redirect_back(fallback_location:, allow_other_host: true, **args)

  • :fallback_location- The default fallback location that will be used on missing Referer header.

  • :allow_other_host - Allow or disallow redirection to the host that is different to the current host, defaults to true.

  • All other options that can be passed to redirect_to are accepted as options and the behavior is identical.

    And redirect_to allows me to add params to the url just by passing them as a hash

    So, why do none of these work for me:

  • redirect_back fallback_location: tasks_path, allow_other_host: false, syncing: true
  • redirect_back fallback_location: tasks_path, allow_other_host: false, { syncing: true }
  • redirect_back fallback_location: tasks_path, allow_other_host: false, options: { syncing: true }
  • redirect_back(fallback_location: tasks_path, allow_other_host: false, options: { syncing: true })
  • redirect_back(fallback_location: tasks_path, allow_other_host: false, syncing: true)
  • ...and any other iteration on the above that I could think of.

    All of them (that are valid code), just return me back without the added parameter

    I'm trying to achieve this URL: (back_url or fallback_location) + '?syncing=true'

    like image 899
    Chiperific Avatar asked Dec 18 '22 22:12

    Chiperific


    1 Answers

    If you look at the source code for redirect_back you will see, that it essentially uses redirect_to "whatever_url.com" version of redirect_to method.

    If you check the explanation of redirect_to you can see that in this use case you unfortunately cannot pass any arguments. If this is super needed, I guess you could just override the redirect_back method to append params option to the url with string concatenation, but that seems like a nasty fix.

    But to answer your question - what you want to achieve seems to be impossible out of the box.

    like image 172
    Kkulikovskis Avatar answered Apr 20 '23 01:04

    Kkulikovskis