Have studied Ruby. Unable to understand Routing and Associations. Can anybody help

I visited ‘rails.org’. I understood “Getting started with rails” but all other topics are useless. They do not make any sense because they are not enlisted series wise. Can any body help me out. I want to learn Rails step by step .Please help.

Work right through a good tutorial such as railstutorial.org, which is free to use online


I don’t know what is meant by “not enlisted series wise” means, but, Colin’s advice notwithstanding, there are guides on routing and on associations, listed here: https://guides.rubyonrails.org/

  1. Rails Routing from the Outside In.

  2. Active Record Associations.

Hey Pankaj!

If you are completely new to Rails, I would recommend you to go through this short interactive course http://railsforzombies.org . It helped me a lot by chilling things down when I started learning RoR about 18 months ago. Once you’ve basics cleared up, I don’t know of any better documentation than railstutorial.org as Colin mentioned.

I hope that helped. :blush:

Amarjeet Singh Mudhar

Hi, Pankaj!

I don’t know whether you had web programming experience before, such as PHP or some others. As you know, Rails is a framework that helps in building Web applications. You type some words and punctuators into the ‘address bar’ in your browser, and get a page as response from server. What you typed is known as ‘Internet address’, part of which in form of ‘www.xxx.com’ is called ‘domain’ (not precisely). The other part after the domain name is what router handles with.

If you type ‘guides.rubyonrails.org/activerecord/associations’ in browser’s address bar, the process of rails matches ‘/activerecord/associations’ with the rules written in routes file. And rails chooses matched controller and method to tackle with data user sent, fetching data from database, render template, and finally returns a complete page to user. This is what router does. In the MVC model, this works in the Controller part.

Data associations is another important topic in web applications. Almost all user data are stored in databases, most of which are relational databases. A database consists of many tables. Just understand in this way:

  • A rails application uses one database
  • A database has many tables
  • A table are mapped to a model
  • A model describes some kind of entity, such as ‘person’, ‘book’ or ‘user’
  • Models are associated by associations, and there are many kinds of associations as listed in the rails guides page. For example, a person may have many books, but a book can only belong to one person. So this is a ‘one to many’ association. Rails makes abstraction of it, in order to write code like ‘person.books.each { |book| xxx }’. More elegant and convenient.
  • Association is usually talked in the model level. How is this actually implemented is not main issue we are interested in.

Both of routing and associations is related to many topics around web development and computer science. In order to know more about routing, you’d better learn how HTTP works and something about Rack. For associations, deep understanding of relational databases is helpful for using it well. Fortunately, rails did many for us. This is why so many people love it. Enjoy learning and using Rails!

Qiu Chaofan

在 2017年3月7日星期二 UTC+8上午4:01:04,pankaj kumarji写道: