Ruby for Rails: Ruby Techniques for Rails Developers
Fullstack LMS: Ruby on Rails 7, Hotwire, Tailwind, Stripe, PostgreSQL
A framework user’s–eye view of application development
- Describe and model your application’s domain. The domain is the universe of
your application. The domain may be music store, university, dating service,
address book, or hardware inventory. Whatever it is, you have to figure out
what’s in it—what entities exist in this universe—and how the items in it
relate to each other. The domain description you come up with will guide
the design of your database (which you’ll need to create and initialize using
the administrative tools provided by the database system) as well as some of
the particulars of the Rails application.
- Specify what can happen in this domain. The domain model is static; it’s just
things. Now you have to get dynamic. Addresses can be added to an address
book. Musical scores can be purchased from music stores. Users can log in
to a dating service. Students can register for classes at a university. You need
to identify all the possible scenarios or actions that the elements of your
domain can participate in.
- Choose and design the publicly available views of the domain. At this point, you
can start thinking in Web-browser terms. Once you’ve decided that your
domain has students, and that they can register for classes, you can envi-
sion a welcome page, a registration page, and a confirmation page. Cus-
tomers shopping for shoes may have access to a style selector, a shopping
cart, and a checkout page. Each of these pages, or views, shows the user
how things stand at a certain point along the way in one of your domain’s
scenarios. You have to decide which views will exist.
Introducing the MVC framework concept
- Model—The parts of the application that define the entities that play a role
in the universe of the application (books, hammers, shopping carts, stu-
dents, and so on)
- Controller—The facility within the application that directs traffic, on the one
hand querying the models for specific data, and on the other hand organiz-
ing that data (searching, sorting, massaging it) into a form that fits the
needs of a given view
- View—A presentation of data in a particular format, triggered by a control-
ler’s decision to present the data
Overview of how Rails implements the MVC framework design
MVC phase |
Rails sublibrary |
Purpose |
Model |
ActiveRecord |
Provides an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records. Ruby method names are automatically generated from the field names of data-base tables, and so on. |
View |
ActionView |
An Embedded Ruby ( ERb ) based system for defining presentation templates for data presentation. Every Web connection to a Rails application results in the displaying of a view. |
Controller |
ActionController |
A data broker sitting between ActiveRecord (the database interface) and ActionView (the presentation engine). ActionController provides facilities for manipulating and organizing data from the database and/or from Web form input, which it then hands off to ActionView for template insertion and display. |
The Basics of Rack for Ruby