Reputation: 2807
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.
Upvotes: 5
Views: 10337
Reputation: 1030
Rails components:
Upvotes: 9
Reputation: 11232
Rails components are modules which are included by default in application.rb
with require rails/all
:
validates :name, presence: true
) [].blank?
) Upvotes: 14
Reputation: 3210
In your rails app, these are all require
d. For example if you run a rails command in your application, through script/rails command
, the script/rails
requires config/boot
which requires bundler
and then executes Bundler.setup
which requires all the gems in your Gemfile
.
Upvotes: 5
Reputation: 11552
Go to this page Github Rails Page and under each one, you have a detailed explanation about their purpose.
Upvotes: 8