-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error rendering XML when render_nil is set to true and value is nil. #150
Comments
Please try this with separate representers (one for XML, only) and give me a complete test setup so I have a chance to understand what you're doing (No test, just some pseudo code is ok). BTW: You don't need to |
let me simplify a bit - so I don't get into how I implemented restrictions - as this bug happens whenever an associated Representer doesn't have anything to render - in this case manufacturer_id is nil and therefore associated manufacture is also nil - and I say render it as blank class ProductRepresenter < Roar::Decorator
include Roar::XML
self.representation_wrap= nil
Product.attribute_names.each do |attr|
property attr, render_nil: true
end
property :manufacturer, class: Manufacturer, decorator: ManufacturerRepresenter, render_nil: true
end
class ManufacturerRepresenter < Roar::Decorator
include Roar::XML
self.representation_wrap= nil
property :id
property :name
property :code
end
class Product < ActiveRecord::Base
belongs_to :manufacturer, inverse_of: :products
end
class Manufacturer < ActiveRecord::Base
has_many :products, inverse_of: :manufacturer
end
class ProductsController < ApplicationController
include Roar::Rails::ControllerAdditions
%w(json xml).each do |response|
represents response.to_sym, Product
end
respond_to :html, :json, :xml
def show
product = Product.include_all.find_by_id(params[:id])
#include_all is a scope that eager loads all related associations
#( I don't want to call it using default scope - as that slows down
# all other lookups that don't need this level of detail)
respond_with product
end
end So when I call http://api.dev/products/1.xml and product doesn't have a manufacturer for instance - than I get that error above. THis only happens in XML, not in JSON - |
Code:
here is the error
The text was updated successfully, but these errors were encountered: