Correctly pass resource for simple render. Only fetch template name

when needed
This commit is contained in:
ccocchi 2012-09-20 13:07:18 +02:00
parent 85eb4ebbf7
commit 137234e705
1 changed files with 8 additions and 2 deletions

View File

@ -7,13 +7,19 @@ module RablRails
class Responder < ActionController::Responder class Responder < ActionController::Responder
def initialize(controller, resources, options = {}) def initialize(controller, resources, options = {})
super super
@api_template = @controller.respond_to?(:responder_default_template, true) ? controller.send(:responder_default_template) : nil if options[:locals]
options[:locals][:resource] = resource
else
options[:locals] = { resource: resource }
end
end end
protected protected
def api_behavior(error) def api_behavior(error)
rabl_options = options.merge(template: @api_template || RablRails.responder_default_template, locals: { resource: resource }) template = @controller.respond_to?(:responder_default_template, true) ? controller.send(:responder_default_template)
: RablRails.responder_default_template
rabl_options = options.merge(template: template)
if get? if get?
controller.default_render rabl_options controller.default_render rabl_options