jbuilder access to nested models

时间:2018-02-26 17:36:13

标签: ruby-on-rails json jbuilder

class Parent

belongs_to :condition
has_many   :conditionregions, through: :condition

class Condition

translates :description, :fallbacks_for_empty_translations => true
globalize_accessors

class Conditionregion

belongs_to :region

With jbuilder the associations can be chained on parent defined relatives, including translations,

json.conditionregions @event.condition.conditionregions, :region_id
json.translations @event.condition.translations, :locale, :description

However, extracting the related data of a relation returns a NoMethodError undefined methodregion`

json.regions @event.condition.conditionregions.region, :name

How can this latter information be accessed? Must the model also chain down (and how to do so?) or is there a syntaxic hoop to jump through?

0 个答案:

没有答案