Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the submit button to link to another page in rails

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?

like image 662
Steve Avatar asked Mar 24 '10 06:03

Steve


People also ask

How do I link a submit button to another page?

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.


1 Answers

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
like image 168
John Topley Avatar answered Oct 23 '22 05:10

John Topley