rabl icon indicating copy to clipboard operation
rabl copied to clipboard

Extended template @object is nil

Open aforty opened this issue 10 years ago • 2 comments

Been pulling my hair out for a few hours but I bet there's a simple solution for this. I'm trying to re-use the 'show' template in my 'search' template.

search.rabl

collection @retailers

extends 'api/v2/retailers/show'

show.rabl

object @retailer

attributes :id, :slug

child :stock_location => :location do
  attributes :address1, :address2, :city, :state, :country

  child @retailer.profile => :point do
    attributes :lat => :latitude
    attributes :long => :longitude
  end
end

Here's the error that I get:

 Rendered api/v2/retailers/search.rabl (2.7ms)
undefined method `profile' for nil:NilClass
/local/path/to/rails-app/app/views/api/v2/retailers/show.rabl:8:in `block in render'

aforty avatar Apr 10 '15 22:04 aforty

Also don't ask me why these two data-points exist in separate classes/tables.

aforty avatar Apr 10 '15 22:04 aforty

Please replace @retailer with locals[:object]. Or you can "puts locals" in the show.rabl for fun.

yangzhichina avatar Jun 17 '15 06:06 yangzhichina