Ruby on Rails
HowtoCascadeViewsForAmorphousData (Version #2)

Say you want to show details of your customers in your web app. Not an uncommon task, isn’t it?
Your customer data comprises of

  • a name and personal data
  • several electronic adresses
  • several postal adresses
  • a collection of projects on which the customer works on
    So you have amorphous data for your customer, that maybe scattered around various tables. But you have a customer entity that holds them all together.
    Now… what if you want separate views that “know” for themselves how to display the personal data or an electronical address or a postal address? How do you incorporate various “subviews” that all use their own templates to show their data?
    Can anyone shed light on this? Maybe with a little Rails background?
    coops says – This is what Components can be used for. Components are like these ‘sub views’ you desire. They’re basically entire actions/views that can be placed wherever you like within another action/view.
    dennis says – IMO plain partials are much better suited for this case. Just create partials which iterate over a given array of elements (addresses, projects, whatever) and display the data. Why should one have to use components for that?
    tlucas says – If the data gathering process is not trivial then you could methods to your model which gather the data and return value objects. You could then make some partials which render the value objects.
    This sould be cleared out in the wiki, I am also dissapointed how to do this. It affects reusability very hardly

Say you want to show details of your customers in your web app. Not an uncommon task, isn’t it?
Your customer data comprises of

  • a name and personal data
  • several electronic adresses
  • several postal adresses
  • a collection of projects on which the customer works on
    So you have amorphous data for your customer, that maybe scattered around various tables. But you have a customer entity that holds them all together.
    Now… what if you want separate views that “know” for themselves how to display the personal data or an electronical address or a postal address? How do you incorporate various “subviews” that all use their own templates to show their data?
    Can anyone shed light on this? Maybe with a little Rails background?
    coops says – This is what Components can be used for. Components are like these ‘sub views’ you desire. They’re basically entire actions/views that can be placed wherever you like within another action/view.
    dennis says – IMO plain partials are much better suited for this case. Just create partials which iterate over a given array of elements (addresses, projects, whatever) and display the data. Why should one have to use components for that?
    tlucas says – If the data gathering process is not trivial then you could methods to your model which gather the data and return value objects. You could then make some partials which render the value objects.
    This sould be cleared out in the wiki, I am also dissapointed how to do this. It affects reusability very hardly