Part I - Getting Started

Chapter 2. Instant Gratification

check project's dependencies/version/etc

When in a rails project dir, check the version of what you have using

rails about

access dev server over the network

Enabling the server to be accessed over the network:

config/environments/development.rb:

config.hosts.clear

Also specify the host to bind with:

rails server -b 0.0.0.0

show web console even when accessing from another host

config/environments/development.rb:

config.web_console.whitelisted_ips = %w(0.0.0.0/0 ::/0)
Important

Web Console has a Path Match input field!!

auto-create controller/actions/views

Create a controller defining some actions (and, consequently, the views):

rails generate controller Say hello goodbye

Chapter 3. The Architecture of Rails Applications

MVC: Model

The model is responsible for maintaining the state of the application. Sometimes this state is transient, lasting for just a couple of interactions with the user. Sometimes the state is permanent and is stored outside the application, often in a database

A model is more than data; it enforces all the business rules that apply to that data. (...) By putting the implementation of business rules in the model, we make sure that nothing else in the application can make our data invalid. The model acts as both a gatekeeper and a data store.

The model layer is the gatekeeper between the world of code and the database. Nothing to do with our application comes out of the database or gets stored into the database that doesn't first go through the model.

MVC: View

By embedding code in the view, we risk adding logic that should be in the model or the controller. As with everything, while judicious use in moderation is healthy, overuse can become a problem. Maintaining a clean separation of concerns is part of the developer's job.

MVC: Controller

The Rails controller is the logical center of your application. It coordinates the interaction among the user, the views, and the model.

Action Pack: The View and Controller

The controller supplies data to the view, and the controller receives events from the pages generated by the views. Because of these interactions, support for views and controllers is bundled into a single component, Action Pack.

Chapter 4. Introduction to Ruby

Here I'm just taking notes of what is not yet embedded in my brain.

Protected methods

Protected methods can be called both in the same instance and by other instances of the same class and its subclasses.

Modules

Modules serve two purposes:

  1. Act as a namespace, letting you define methods whose names won't clash with those defined elsewhere.
  2. Allow sharing functionality among classes.

(...) Multiple classes can mix in the same module, sharing the module's functionality without using inheritance. You can also mix multiple modules into a single class.

Assignment shortcuts a op= b

Just like a += b is equivalent to a = a + b

a ||= b is a shortcut for a = a || b

So count ||= 0 gives count the value 0 if count is nil or false.