Rails and Django share many concepts. For more conceptual notation, visit my Django-Tutorial repository.
The philosophy between Rails and Django are incredibly similar. From my research, the differences that spawn Rails development over Django are mostly driven by opinion specifically when concerning application routing and Rails' "Convention over Configuration". This is really the key philosophical difference, here, that drives the majority of programming differences between it and Django. By "convention", Rails includes tools such as Coffeescript, Sass, and the jQuery Unobtrusive Adapter out of the box. However, Django's emphasis on user configuration seems to allow for more freedom for seasoned developers.
following "Getting Started with Rails"
from: https://brew.sh
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
(RECOMMENDED)
Note: in order to install rbenv
, you may need to uninstall RVM
. This StackOverflow Response proved to be a very useful guide to doing so...
Note: in order to completely remove RVM
, I had to modify my $PATH
by:
- perform
echo $PATH
in your terminal - copy the output and remove all directories including
.../.rvm/...
in a text editor - copy the new
$PATH
- perform command in terminal
export PATH=<paste_new_$PATH>
- restart Terminal (or iTerm)
- check
gem
is pointing to the right directory using:
gem env home
# /Users/<username>/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0
from: https://gorails.com
brew install rbenv ruby-build
# Add rbenv to bash so that it loads every time you open terminal
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
# reload the ~/.bash_profile file
source ~/.bash_profile
# Update Ruby
rbenv install 2.4.1
rbenv global 2.4.1
# Verify Ruby was installed
ruby -v
gem install rails
In the project directory, run:
rails new <app_name>
cd <app_name>
bin/rails server
Using your favorite browser (please! no IE), type localhost:3000
Note: the development server reloads your files on every save while in the development environment
- handles requests for the given application
- routing determines which controller receives which requests
config/routes.rb
- documentation
- action collects and serves information to views
- routing determines which controller receives which requests
- collects information
- it is convention to implement CRUD actions in this order:
- index, show, new, edit, create, update, destroy
Within the Rails application directory:
bin/rails generate controller <controller_name> <action_name>
Note: also generates an action called <action_name>
(optional)
- handles how information is displayed
- uses eRuby (Embedded Ruby) to write view templates
- uses the
.erb
file extension
- uses the
- supports partial files to prevent duplication in templates
- by convention, partial file names begin with an
_
(underscore)- Example:
.../_<fileName>.html.erb
- Example:
- heavily uses Resource-Oriented Style
- by convention, partial file names begin with an
- manages databases for the application
- concept includes both
models/
anddb/
directories
- concept includes both
- migrations ruby classes designed to create and modify database tables
- Rails uses
rake
commands to run migrations - naming convention includes a timestamp
- Example:
db/migrate/YYYYMMDDHHMMSS_<action_name>_<model_name>.rb
- Example:
- actions defined in Rails generated migration are reversible
- Rails uses
- includes data validation methods documentation
- supports Active Record Association
Within the Rails application directory:
bin/rails generate model <model_name> <attribute>:<type>
Note: also generates an attribute called of type (optional)
Within the Rails application directory:
bin/rails db:migrate
Note: command only functional in the development environment
- Rails supports basic HTTP Authentication
- add-on authentication gems may also be used
- More on Rails Authentication & Security
- MacOS v10.12.5
- Atom.io v1.17.2
- iTerm2 v3.0.15
- Ruby v2.4.1p111
- Homebrew v1.2.1
- rbenv v1.1.0
- Ruby on Rails v5.1.1
- SQLite3 v3.16.0
- Excellent Atom.io Rails development packages discussion