0

I've been learning Ruby on Rails for quite some time now and have built several toy applications. I've taken many classes/courses (i.e., Hartl, Code School, Udemy, etc.). Now I'm working on a pet project that is fairly complex - many models and relationships.

Here's my question: How do I go about thinking about a complex application in terms of models and relationships? It seems to me there should be some visual way to model all of this, but I haven't seen any discussion of such modeling in any of the classes I've taken. Sure, there's the very simple diagrams in the Rails Guides, but how do I extend this to something more complex? Or, am I making this too complicated? Do I just start coding models and relationships and see where it takes me? It seems this ad hoc approach could easily paint me into a corner where I'll have to start over from scratch if I paint myself into a corner, so to speak.

Are there tools or blog posts that can help me?

(Note: I've also posted this question at Reddit.Com/r/Rails at https://www.reddit.com/r/rails/comments/7c9zbf/how_to_think_about_rails_web_application/)

Clint Laskowski
  • 149
  • 1
  • 3
  • 13
  • 1
    I don't know what answer you're hoping for. A list of books, videos, blogs, etc about rails? A link to a tutorial about database diagrams? Personal opinions about how to design applications? It's not a very specific question, so I don't know how to answer it. – Tom Lord Nov 11 '17 at 18:46

2 Answers2

3

It sounds like what you're after is a schema designer. I'll link one at the bottom of this post. A schema designer will allow you to visualize all the relationships in your application, and see how one model connects to another. They're really helpful in writing complex DB queries. I've attached an example of a fairly simple design just to give you an idea what they do.You can also add all the columns a model has in the design, I just usually use it more for relationships. http://ondras.zarovi.cz/sql/demo/ schema expample

Aram
  • 56
  • 3
1

Purely based on my experience/opinion...

You'll end up changing your database design a couple of times as you build your app.

I would start with a whiteboard, then consider using a schema designer as @aram mentioned.

After you see the big picture, just start with the relationships that what you need for today's features. You can keep referring to the original design, so you can see the bigger picture, but you don't want to overbloat your architecture before you need to because it will change.

After you write some code and build those relationships, you can spot check yourself using the rails-erd gem to programmatically generate your app's schema.

Zubin
  • 393
  • 1
  • 3
  • 7
  • While I gave @Aram credit for the answer, I want to say "thank you" for your answer, especially for the mention of the rails-erd Gem. Really nice to see my models as a diagram! – Clint Laskowski Nov 12 '17 at 01:11