Home > Software design >  How to make a redirect to external URLs when visiting URLs in my webapp Using Rails 7
How to make a redirect to external URLs when visiting URLs in my webapp Using Rails 7

Time:02-18

I am learning RoR by building a job board, so I am trying to redirect to external URL when someone visits show page of my Rails job. I am trying to do below logic,

Click on show page link -> Check if Description available -> Yes (Then go to show page) -> No (Then go to show page URL which then automatically redirects to corresponding External URL associated with the post)

Please help me with this. Thank You.

CodePudding user response:

In your show action, you can use this method

redirect_to 'https://stackoverflow.com', allow_other_host: true

Read More : https://api.rubyonrails.org/classes/ActionController/Redirecting.html#method-i-redirect_to

  • Related