Class: Cuprum::Rails::Responses::Html::RedirectBackResponse
- Inherits:
-
Object
- Object
- Cuprum::Rails::Responses::Html::RedirectBackResponse
- Defined in:
- lib/cuprum/rails/responses/html/redirect_back_response.rb
Overview
Encapsulates an HTML response that redirects to the previous path.
Instance Attribute Summary collapse
-
#fallback_location ⇒ String
readonly
The path or url to redirect to if the previous location cannot be determined.
-
#flash ⇒ Hash
readonly
The flash messages to set.
-
#status ⇒ Integer
readonly
The HTTP status of the response.
Instance Method Summary collapse
-
#call(renderer) ⇒ Object
Calls the renderer’s #redirect_back_or_to method with the status.
-
#initialize(fallback_location: '/', flash: {}, status: 302) ⇒ RedirectBackResponse
constructor
A new instance of RedirectBackResponse.
Constructor Details
#initialize(fallback_location: '/', flash: {}, status: 302) ⇒ RedirectBackResponse
Returns a new instance of RedirectBackResponse.
12 13 14 15 16 |
# File 'lib/cuprum/rails/responses/html/redirect_back_response.rb', line 12 def initialize(fallback_location: '/', flash: {}, status: 302) @fallback_location = fallback_location @flash = flash @status = status end |
Instance Attribute Details
#fallback_location ⇒ String (readonly)
Returns the path or url to redirect to if the previous location cannot be determined.
20 21 22 |
# File 'lib/cuprum/rails/responses/html/redirect_back_response.rb', line 20 def fallback_location @fallback_location end |
#flash ⇒ Hash (readonly)
Returns the flash messages to set.
23 24 25 |
# File 'lib/cuprum/rails/responses/html/redirect_back_response.rb', line 23 def flash @flash end |
#status ⇒ Integer (readonly)
Returns the HTTP status of the response.
26 27 28 |
# File 'lib/cuprum/rails/responses/html/redirect_back_response.rb', line 26 def status @status end |
Instance Method Details
#call(renderer) ⇒ Object
Calls the renderer’s #redirect_back_or_to method with the status.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cuprum/rails/responses/html/redirect_back_response.rb', line 32 def call(renderer) assign_flash(renderer) # :nocov: if Rails.version >= '7.0' # @todo Rails 6 renderer.redirect_back_or_to(fallback_location, status: status) else renderer.redirect_back( fallback_location: fallback_location, status: status ) end # :nocov: end |