module Lucky::Redirectable
Overview
Redirect the request
There are multiple ways to redirect inside of an action. The most common ways are to redirect to a Lucky::Action
class, or a URL/path String
. Both use the #redirect
method:
redirect to: Users::Index
redirect to: Users::Show.with(user.id)
redirect to: "https://luckyframework.org/"
redirect to: "/users"
By default, the method will set the status code to 302
A.K.A. "Found". If you want to customize the status code, you can pass it directly:
redirect to: Users::Index, status: 301
# or use the built in enum value
redirect to: Users::Index, status: :moved_permanently
You can find a list of all of the possible statuses here.
Internally, all the different methods in this module eventually use the
method that takes a String
. However, it's recommended you pass a
Lucky::Action
class if possible because it guarantees runtime safety.
Direct including types
Defined in:
lucky/redirectable.crInstance Method Summary
-
#redirect(to route : Lucky::RouteHelper, status = 302) : Lucky::TextResponse
Redirect using a
Lucky::RouteHelper
-
#redirect(to action : Lucky::Action.class, status = 302) : Lucky::TextResponse
Redirect to a
Lucky::Action
-
#redirect(to path : String, status : HTTP::Status) : Lucky::TextResponse
Redirect to the given path, with a human friendly status
-
#redirect(to path : String, status : Int32 = 302) : Lucky::TextResponse
Redirect to the given path, with an optional
Int32
status
Instance Method Detail
Redirect using a Lucky::RouteHelper
redirect to: Users::Show.with(user.id), status: 301
Redirect to a Lucky::Action
redirect to: Users::Index
Redirect to the given path, with a human friendly status
redirect to: "/users", status: :moved_permanently
You can find a list of all of the possible statuses here.
Redirect to the given path, with an optional Int32
status
redirect to: "/users"
redirect to: "/users/1", status: 301
Note: It's recommended to use the method above that accepts a human friendly version of the status