Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tutorial for Creating Views for ActiveRecord Associations?

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?

like image 798
bento Avatar asked Dec 11 '25 12:12

bento


1 Answers

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.

like image 174
Jim Riordan Avatar answered Dec 14 '25 06:12

Jim Riordan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!