Fabian asked:

Who do I do redirects?

Tags: nitro 0.28

18:35 < Vagabond> okay, how about redirects, like I’ve done some action and I want to go to another page

(1 attempts)

Kashia answered:

There are basically 2 options for that:

  • redirect(destination)
  • redirect_referer

While redirect_referer returns you to your last URL, the redirect will move you to the argument you give it.

h3. Example

class MyController < Nitro::Controller
  def login
    # ... return to referrer after logging in
    redirect_referer
  end

  def logout
    # .. after logging out, go to the main page
    redirect '/'
  end
end

Rating: 5