Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly are the "components" of Rails (ActiveRecord, ActionController, etc.)?

I just started learning Rails and Ruby. The Ruby on Rails Guide at http://guides.rubyonrails.org/getting_started.html says that Rails consists of many different "components". Some of these components, such as ActiveRecord and ActionController, I've encountered in my Rails apps (in models and controllers, respectively).

The relevant syntax ("class Model < ActiveRecord::Base" and "class ApplicationController < ActionController::Base") make it look like these components are Ruby modules, but if they are modules in which files are they located? And how can we reference them without first using the Ruby method "require"?

UPDATE: So I found all of the built-in modules and classes. On my server, the path for the Base class of the ActiveRecord module (for example) is:

/usr/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/active_record

But I still don't know why we can refer to these modules and classes in our models and controllers without first using Ruby's require method.

like image 396
zjmiller Avatar asked Nov 28 '22 03:11

zjmiller


1 Answers

Rails components are modules which are included by default in application.rb with require rails/all:

  • action mailer is a module for designing email service layers
  • action pack is a module for handling and responding to web requests (includes action_controller, action_dispatch)
  • action view is a module for handling view template lookup and rendering
  • active job is a module for declaring jobs and making them run on a variety of queueing backends
  • active model is non-database functionality extracted from Rails 2 Active Record (validates :name, presence: true)
  • active record connects classes to relational database tables (migrations, associations)
  • active support contains all Ruby extensions ([].blank?)
like image 167
lakesare Avatar answered May 25 '23 06:05

lakesare