3

In teaching Rails students I often arrive at the point where they've created two models and set up an association and are wondering how they can make that association visible in the views.

Now my question is, are there any overview articles / tutorials / blog posts for this,

which give an overview of the different ways to show Associations in the views. For example, I see several "Association Patterns", that are, a

  • 1:n association could be Aggregation or Composition as described in the UML with different implications for creation of associated entities (which might point to nested resources, only discussed in terms of routing)
  • ... or something like belonging to a category etc. where you would want to choose from existing options or create a new one if the desired entity is not found; which is handled by first_or_create, but again, I haven't seen any documentation summarizing different options for that in the view (as RailsCast #57 and 258 describe, for example.)

I have tried searching for it. Also, neither Michael Hartl's Tutorial or the PragProgs "Agile Web Development with Rails" have something like that.

So, is there something out there and if not, do people think it would it be useful to create it?

Bishop
  • 296
  • 8
  • 19
bento
  • 2,079
  • 1
  • 16
  • 13
  • Related Question: http://stackoverflow.com/questions/11861289/select-many-box-for-habtm – bento Aug 08 '12 at 09:31

4 Answers4

2

For a more OO / less rails-way discussion of presenting object graphs in views, check out Avdi Grimm's discussion of what he calls the Exhibit pattern:

http://objectsonrails.com/#ID-2656c30c-080a-4a4e-a53e-4fbaad39c262

This has great examples and a good discussion of where and why it might be a good design decision not to follow the pure rails way, if your students are interested in going beyond the API.

Jim Riordan
  • 1,378
  • 11
  • 18
1

Some Railscasts:

bjelli
  • 9,752
  • 4
  • 35
  • 50
1

I wrote a gem for doing nested forms (cocoon), and documented how to solve all types of nested forms in the wiki of the gem. See https://github.com/nathanvda/cocoon/wiki/A-guide-to-doing-nested-model-forms

Hope this helps.

nathanvda
  • 49,707
  • 13
  • 117
  • 139
1

You might want to have them check out the Draper gem. It has excellent documentation and screencasts:

https://github.com/jcasimir/draper

It may not be exactly what you are looking for, but it will teach them about decorator patterns.

I hope this helps!

Renée D
  • 11
  • 1