vendredi 11 septembre 2015

RABL - child not loading

I am having a beast of a time with setting childs using RABL with ruby on rails

I was originally trying some examples in the show.rabl file i saw on the railscast #322 to get child table as a nested node on my json output.

show.json.rabl:

object @entity
attributes *Giving::Entity.column_names


child :address do
  attributes :street, :city
end

I turned on RABL errors and i get "no attribute street exists" in rails console, i see that only the EntitiesController loads, and not the AddressController

So i tried this alternate method show.json.rabl:

object @entity
attributes *Giving::Entity.column_names

child :address do
  extends "giving/v1/addresses/show"
end

addresses/show.rabl:

object @address    
attributes *Giving::Address.column_names

Now, both table columns load, but the Giving::Address Still won't load...It seems to be complaining about a lack of address_id

My models look like this:

class Giving::Entity < ActiveRecord::Base
  self.table_name = "schema.dvl_entity"
  self.primary_key = "id"

  has_many :addresses

end


class Giving::Address < ActiveRecord::Base
  self.table_name = "schema.dvl_address"
  self.primary_key = "address_id"

  belongs_to :entity

end

Any help is greatly appreciated, I am pulling my hair out about this

Aucun commentaire:

Enregistrer un commentaire