I'm sure this is easy once you know rails but I'm new to it...
I want to redirect to another page/action after the submit button (f.submit) is pressed, and only after it is pressed. How do you determine the link that you go to after the submit button is pressed?
To link a submit button to another webpage using HTML Form Tags: Using the HTML Form's Action Attribute, we can link the submit button to a separate page in the HTML Form element. Here, declare/write the “Submit button” within HTML Form Tags and give the File Path inside the HTML form's action property.
Submit buttons are used to submit forms to a controller action. In the controller action you can use the redirect_to
method to redirect to another page.
For example, let's say you have a form for creating widgets. That form would typically submit to the create
action in the WidgetsController
, which could redirect to a listing of widgets that would include the newly created widget:
class WidgetsController < ApplicationController
...
def create
# Do stuff to create the Widget
...
redirect_to widgets_path # Redirects to /widgets
end
end
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