Chapter 1 Flashcards
What is rails?
web development framework written in the ruby programming language
installing rails with a specific version number
$ gem install rails -v 4.2.2
-v flag
ensures the specified version gets installed
shell command:
change to home directory
make a workspace directory
then change into it
$ cd # Change to the home directory.
$ mkdir workspace # Make a workspace directory.
$ cd workspace/ # Change into the workspace directory.
what is bash
shell comman line interface
shell: list contents
ls: $ls -l
make directory shell
mkdir : $ mkdir workspace
shell:change directory
cd : $ cd workspace/
shell cd one directory up
$ cd..
shell cd to home directory
$ cd ~ or just $ cd
cd to path including home directory
$cd ~/workspace/
move file(rename) shell
mv : $mv README.rdoc README.md
copy file in shell
cd : $ cp README.rdoc README.md
remove file
rm : $ rm README.rdoc
remove empty directory shell
rmdir : $ rmdir workspace/
remove nonempty directory
rm -rf : $ rm -rf tmp/
concatenate and display file contents
cat : $ cat ~/.ssh/id_rsa.pub
command to run rails at version 4.2.2
rails 4.2.2 new hello_app
app/
core application code, including models, views, controllers, and helpers
app/assets
assets such as CSS, JavaScript files, and images
bin/
binary executable files
config
application configuration
db/
database files
doc/
documentation for the application
lib/
library modules
lib/assets
library assets such as CSS, JavaScript files, and images
log/
app log files
public/
data accessible to the public (e.g., via web browsers), such as error pages
bin/rails
a program for generating code, opening console sessions, or starting a local server
test/
app tests
tmp/
temporary files
vendor/
third-party code such as plugins and gems
vendor/assets
third-party assets such as CSS, JavaScript files, and images
README.rdoc
a brief description of the application
rakefile
Utility tasks available via the rake command
Gemfile
Gem requirements for this app
Gemfile.lock
a list of gems used to ensure that all copies of the app use the same gem versions
config.ru
a configuration file for Rack middleware
.gitignore
patterns for files that should be ignored by Git
gem ‘sqlite3’
install latest version of gem
gem ‘uglifier’, ‘>= 1.3.0’
ugligier(handles file compression for the asset pipeline) installs as long as its greater than or equal to version 1.3.0
gem ‘coffee-rails’, ‘~> 4.0.0’
installs gem as long as its newer than 4.0.0 and not newer than 4.1 (minor point releases)
bundle install
install and include the gems needed by the app
command for running rails on local system
rails server
rails follows what architectural pattern?
model-view-controller (MVC) pattern
MVC
enforces a separaton between “domain” logic from the input and presentation logic associated with GUI.
Domain logic: data models like users, articles, and products.
GUI: web page in a web browser
basic interaction with rails app: (long answer)
browser sends a request, received by a web server and passed on to a rails controller, which is in charge of what to do next. controller might render a view html. dynamic sites: the controller interacts with a model which is a ruby object that represents an element of the site(such as a user). and is in charge of communicating with the database. after invoking the model, the controller renders view and returns the web page to the browser as HTML
what is version control?
allow us to track changes to our projects code, collaborate more easily, and roll back any errors such as deleting files
what is git?
distributed version control
you can have multiple controllers for an application(t/f)
true. we will create some in chapter 2 =)
explain:
def hello
render text: “hello”
end
define a function which uses the render function to return the text
rails router?
sits in front of the controller and determines where to send requests that come in from the browser
root route?
determines the page that is served on the root URL
root ‘application#hello’
setting the root route: application is the controller name and hello is the action within that controller
git system setup
$ git config –global user.name “Your Name”
$ git config –global user.email your.email@example.com
git initialize a repository
$ git init
add all project files to the repository
$ git add -A (adds all files in the current directory apart from .gitignore.
where are git added files in the repository placed?
staging area which contains pending changes to your project
git status
see files in staging area
$ git commit -m “Initialize repository”
tell git to keep the changes from the staging area. -m flag lets you add a message for the commit
where are git commits stored?
locally. you have to push the changes up to a remote repository.
see list of commit messages:
$ git log
rm -rf app/controllers
rm to remove directory and rf flag means “recursive force” which recursively removes all files, diretories, subdirectories, and so on without asking explicit confirmation of each deletion
process to get back deleted files in git
we deleted controller directory, but the changes are only on the ‘working tree’; they havent been commited yet (git status shows that). we can still undo the changes using checkout command with the -f flag to force overwriting the current changes
git checkout -f
undo changed and -f force overwriting the current changes
github
social coding site optimized for hosting and sharing git repositories. ability to work on open source projects
why put repositories on github
its a full backup of your code (including full history of commits), and it makes any future collaboration much easier.
SSH keys
ways to identify trusted computers without involving passwords.
what is version control?
system that records changes a file or set of files over time so that you can recall specific versions later.
ls -al ~/.ssh
lists the files in your .ssh directory
git remote add origin https://github.com/saweel/rails_intro.git
tells git you want to add github as the origin for your master branch. rails_intro is the repository name on your github account
git push -u origin master
push your repository up to github (dont worry about -u)
branch:
effectively copies of a repository where we can make changes without modifying the parent files.
git checkout -b modify-README
creates new branch and switches to it
git branch
lists all the local branches and * tells you which branch your on
git commit -a -m “Improve the README file”
-a flag as shortcut for committing all modifications to existing files. commit changes to staging area
git checkout master
git merge modify-README
switch to branch ‘master’
and merge branch together (still in staging area)
git branch -d modify-README
delete branch
# For illustration only; don't do this unless you mess up a branch $ git checkout -b topic-branch $ $ git add -A $ git commit -a -m "Major screw up" $ git checkout master $ git branch -D topic-branch
major screw up and need to abandon topic branch. -D will delete branch even though we havent merged in the changes
git push
push changes to github. we could have said git push origin master, but since we already done one push, we can omit it
heroku
hosted platform for deploying rails and other web applications using a cloud platform
heroku login
login onto heroku
heroku keys:add
add ssh keys
heroku create
create a place on heroku servers for the sample app to live. creates new subdomain.
git push heroku master
put master branch up to heroku