Override Responder#to_format to avoid first missing render on POST
request. Fallback to default Rails responder behavior if template is not found
This commit is contained in:
parent
0cf1efea14
commit
35d21b38e6
@ -14,20 +14,33 @@ module RablRails
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_format
|
||||||
|
if get? || response_overridden?
|
||||||
|
default_render
|
||||||
|
elsif has_errors?
|
||||||
|
display_errors
|
||||||
|
else
|
||||||
|
api_behavior(nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def api_behavior(error)
|
def api_behavior(error)
|
||||||
template = @controller.respond_to?(:responder_default_template, true) ? controller.send(:responder_default_template)
|
if post?
|
||||||
: RablRails.responder_default_template
|
template = if @controller.respond_to?(:responder_default_template, true)
|
||||||
rabl_options = options.merge(template: template)
|
controller.send(:responder_default_template)
|
||||||
|
else
|
||||||
|
RablRails.responder_default_template
|
||||||
|
end
|
||||||
|
options[:template] ||= "#{@controller.controller_name}/#{template}"
|
||||||
|
|
||||||
if get?
|
controller.default_render options.merge(status: :created, location: api_location)
|
||||||
controller.default_render rabl_options
|
|
||||||
elsif post?
|
|
||||||
controller.default_render rabl_options.merge!(status: :created, location: api_location)
|
|
||||||
else
|
else
|
||||||
head :no_content
|
head :no_content
|
||||||
end
|
end
|
||||||
|
rescue ActionView::MissingTemplate => e
|
||||||
|
super(e)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user