views:

330

answers:

1

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?

+1  A: 

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
John Topley