Chapter 1 Flashcards
scaffolding define:
generating code. quicker, easier, more seductive.
ruby on rails:
web development framework written in ruby.
what makes rails so great?
open source. easy to write web applications: generating html, making data models, routing URL’s are easy with rails. also follows REST architectural style. great for rapid prototype
IDE:
integrated development enviroment. programming enviroment consisting of code editor, compiler, debugger, and more. (eclipse)
command to install rails at version 4.2.2
gem install rails -v 4.2.2
-v flag
ensures specified version gets installed
how do we install packages
use gem command provided by the rubygems package manager
bash:
shell command-line interface. (linux command line)
ls -l
lists the contents of the directory. -l lists more
mkdir
creates directory
cd
change directory
cd ..
go up a directory
cd ~ or cd
change to home directory
cd ~/workspace
go to home directory and go to workspace
mv README.rdoc README.md
move file (rename)
cp README.rdoc README.md
copy file
rm README.rdoc
delete file
rmdir workspace
remove empty directory
rm -rf tmp
remove nonempty directory
cat ~/.ssh/id_rsa.pub
display file
command to run rails at specific version
rails 4.2.2 new hello_app
app/
core application code, including models, views, controllers, and helpers
app/assets
applications assets such as css, javascript, and images
bin/
binary executable files
cofig/
application configuration
db/
database files
doc/
documentation for the application
lib/
library modules
lib/assets
library assets such as css, javascript, and images
log/
application log files
public/
data accessible to the public (via web browser) such as error pages
bin/rails
a program for generating code, opening console sessions, or starting a local server
test/
application tests
tmp/
temporary files
vendor/
third-party code such as plugins and gems
vendor/assets
thirst party assets such as css, javascript, 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
bundler
used to install included gems needed by the app.
gem ‘sqlite3’
install latest version of this gem
gem ‘ugligier’, ‘>=1.3.0’
(handles file compression for the asset pipeline). install gem as long as its greater than or equal to the version specified.
gem ‘coffee-rails’, ‘~> 4.0.0’
install gem as long as its newer than version 4.0.0 and not newer than 4.1 (minor point releases). 4.0.0 to 4.0.1 is ok, but 4.0 to 4.1 is not
command to use bundler
bundle install
running rails in cloud9 command
rails server -b $IP -p $PORT
MVC model
enforces separation between domain logic (data models) and the presentation logic (web page)
interaction with rails application:
browser sends request which is received by web server and passed on to a rails controller, which is in charge of what to do next. controller interacts with model, which is ruby object that represents an element of the site and is in charge of communication with the database. the controller then renders the view and returns the complete web page to the browser
define an action to render a string
def hello render text: "hello" end
rails router
determines where to send requests that come in from the browser.
root route:
page that is the root URL
create root route to application_controller.rb, hello action
root ‘application#hello’. tells rails to send the root route to the hello action in the application controller
version control
allows us to track changes to our projects code, collaborate more easily, and roll back any errors.
git
distributed version control system
before using git for the first time, what do you need to do
need to do one-time setup. these are system steps, you do them once per computer
git system setup steps:
git config –global user.name “your name”
git config –global user.email your.email@example.com
git config –global push.default matching
git config –global alia.co checkout. the name and email will be available in any repository you make public
git config –global push.default matching
ensures forward-compatibility with an upcoming release of Git.
git config –global alias.co checkout
use co in place of the more verbose checkout command
initialize a repository
git init
git add -A
add all the project files to the repository apart from those that match the patterns in a special file called .gitignore
git status
see files in staging area (changes to be committed (changes to be kept in repository))
git commit -m “Initialize repository”
tells git to keep changes and -m flags lets you add messages for the commit
git log
list of commit messages
ls app/controllers
rm -rm app/controllers
ls app/controllers
deleted app/controllers which is critical. but it is only in the working tree; they havent been committed yet so you can get them back with:
git checkout -f
or
git co -f
SSH keys
identify trusted computers without involving passwords
cat ~/.ssh/id_rsa.pub
printing the public key using cat
git remote add origin https://github.com//first_app.git
setup github as the origin for your branch
git push -u origin master
push your repository up to github
branch, edit, commit, merge workflow
recommonded workflow when using Git
branches
copies of repository where you can make changes without modifying the parent files(master branch).
git checkout -b modify-README
create new topic branch and switch to it
git branch
lists branches
.md
markdown markup language
git commit -a -m “Improve the README file”
git add provides a shortcut -a which is very common for committing all modifications to existing files.
merge branch to master branch
git checkout master
git merge modify-README
delete a branch
git branch -d modify-README
delete branch even though we havent merged any changes
git branch -D topic-branch
delete remote branch
git push origin –delete
Heroku
platform for deploying rails and other web applications. deploying is very easy when your source code is under version control
bundle install –without production
prevent local installation of any production gems
login to heroku command:
heroku login
add key to heroku:
heroku keys:add
create a new application at Heroku
heroku create
use git to push master branch up to heroku
git push heroku master
rename heroku website command:
heroku rename rails-hello-example
(‘a’..’z’).to_a.shuffle[0..7].join
take all values from ‘a’ through ‘z’, convert to array, shuffle whole array and take first 8 indexes and join them to create unique sequence