I want links that when hovered over you see the link to look something like this:
http://www.website.com/redirct_to=linkID2 (maybe not exactly like that but try to get the idea)
I have a form area in my blog that I can input a website url but I want to make it redirect_to an external website when it shows the post.
Create a new model, for example called Link, to store the URLs you want to redirect to. Then generate a new controller (you can use scaffold to generate controller and model at the same time) and change the show action in order to fetch the record with given ID and redirect_to @link. url.
Render tells Rails which view or asset to show a user, without losing access to any variables defined in the controller action. Redirect is different. The redirect_to method tells your browser to send a request to another URL.
In Rails 4. x, for going back to previous page we use redirect_to :back. However sometimes we get ActionController::RedirectBackError exception when HTTP_REFERER is not present. This works well when HTTP_REFERER is present and it redirects to previous page.
redirect_to "https://website.com"
should do it as long as protocol is included. For added flexibility, you can parse it with URI to ensure that all fields are correct. You might want to URI.encode/URI.decode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With