Module: Responders::LocationResponder
- Defined in:
- lib/responders/location_responder.rb
Overview
Responder to accept callable objects as the redirect location. Useful when you want to use the respond_with method with a route that requires persisted objects, but the validation may fail.
class ThingsController < ApplicationController
responders :location, :flash
respond_to :html
def create
@thing = Things.create(params[:thing])
respond_with @thing, location: -> { thing_path(@thing) }
end
end
Instance Method Summary collapse
Instance Method Details
#initialize(controller, resources, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/responders/location_responder.rb', line 17 def initialize(controller, resources, = {}) super if [:location].respond_to?(:call) location = .delete(:location) [:location] = location.call unless has_errors? end end |