Chapter 1 (with some of Chapter 6) Flashcards
How do you create a new gemset in rvm?
Example syntax:
$ rvm use ruby-2.1.5@rails4.2 –create
Once in the gemset, be sure to install rails!
Who created Rails and when?
David Heinemeier Hansson in 2004
What is the command to create a local development server?
$ rails server
What is the first step in designing a new rails app?
Go to your workspace, and run the ‘rails new ‘ command
What is the purpose of each folder generated by ‘rails new’?
app/ Core application (app) code, including models, views, controllers, and helpers
app/assets Applications assets such as cascading style sheets (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 cascading style sheets (CSS), JavaScript files, and images
log/ Application 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/ Application tests
tmp/ Temporary files
vendor/ Third-party code such as plugins and gems
vendor/assets Third-party assets such as cascading style sheets (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
What does ‘bundle install’ do?
It installs and includes the gems needed by the app according to the Gemfile
T/F: ‘bundle install’ is not run at the end of ‘rails new’
F; it is
How can we specify ranges in the Gemfile, and why might we do this?
’>=’ installs the gem as long as it is greater than or equal to the specified version
’~>’ installs the gem as long as it’s newer than the version specified and NOT newer than the next major point release (i.e. 4.0.0 to 4.0.1, NOT 4.0.0 to 4.1.0)
gem ‘uglifier’, ‘>= 1.3.0’
gem ‘coffee-rails’, ‘~> 4.0.0’
It is important that any change in gem can break an application, so this is to be done carefully.
If we change our Gemfile, how can we update the app to reflect the changes?
run ‘$ bundle install’ or, if that fails, ‘$ bundle update’
How can we see our app running on the rails server?
Point your browser to the url given by the server (usually localhost:3000)
What is the MVC architectural pattern?
The “model-view-controller” architectural pattern, which separates “domain logic” from the GUI (input and presentation logic)
What is “domain logic”? What does the GUI refer to?
Also called business logic, it typically consists of data models for things like users, articles, and products, and the GUI is just a web page in a web browser.
Articulate the process of how a rails app interacts with a web browser? What is the difference between a view and a model?
The web browser sends a request, which is received by a web server and passed on to a Rails controller, which is in charge of what to do next. In some cases, the controller will immediately render a view, which is a template that gets converted to HTML and sent back to the browser. More commonly for 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 then renders the view and returns the complete web page to the browser as HTML.
Where can we find controllers, and what are they for?
In the app/controllers directory. They are used for defining controller actions, which is part of what the webpage does.
When defining a controller action (function), what function must be included to return text?
‘render text: “”’
Where can we change where to send browser requests? Why is this important?
By changing the route in config/routes.rb
We can change the page that is served. For example, we can change the page sent by the root URL with the function: ‘root ‘application#’
How do we create a new Git repo?
Navigate to the root directory of the project and run ‘$ git init’
What is the command to add all files to the repo?
$ git add -A
What does ‘$ git status’ do, and how does it relate to the ‘add’ command?
All files that are ‘added’ are placed in a staging area for pending changes, and the status command shows the contents of this staging area
How do we confirm changes with Git?
’$ git commit -m “”’
How do we revert to the last commit?
$ git checkout -f
What is the first step in making a new BitBucket repo?
Create a new private Git repo with a name matching your root directory
What is the command to connect to your repo?
$ git remote add origin git@bitbucket.org:/.git
How do we create a new branch?
$ git checkout -b `
With the ‘$ git branch’ command, what does the ‘*’ in the results indicate?
The current branch
What is the syntax for the first time we push up to our repo?
$ git push -u origin –all
What do the -a and -m flags do in the commit command?
-m sets a message to describe the commit, and -a commits changes to all EXISTING files (files MUST be added with ‘git add -A’ first).
What does ‘git checkout branch’ do?
Switches the active branch.
How do we merge the changes of one test branch to the master branch?
$ git merge
MUST BE IN MASTER BRANCH!
What is the cleanest thing to do once you’ve finished merging a branch?
Delete the branch with ‘$ git branch -d ‘
What needs to be added to the Gemfile in order to use Heroku?
group :production do
gem ‘pg’, ‘0.17.1’
gem ‘rails_12factor’, ‘0.0.2’
end
How do we add out commit to BitBucket?
$ git push
What is the point of the following command?
$ bundle install –without production
It does not install the production gems in the Gemfile, but it adds them to Gemfile.lock. This is mainly for deployment to a production environment, since these gems are not needed for development.
How do we create space for a new application on Heroku?
$ heroku create
How do we deploy to Heroku?
$ git push heroku master
What is the command to change the name of our Heroku deployment, and what will the resulting address be?
$ heroku rename newname.herokuapp.com
How can we view our live site directly from the command line?
$ heroku open
Why is storing hashed values instead of passwords advantageous?
If a database is compromised, user passwords will still be secure.
What does #has_secure_password do, and what does it require to work?
The ability to save a securely hashed password_digest attribute to the database
A pair of virtual attributes (password and password_confirmation), including presence validations upon object creation and a validation requiring that they match
An authenticate method that returns the user when the password is correct (and false otherwise)
The only requirement for has_secure_password to work its magic is for the corresponding model to have an attribute called password_digest.
T/F: The following code is valid:
@user.password = @user.password_confirmation = “a” * 5
T; it is a case of compact multiple assignment
What is a last step when deploying to heroku?
$ heroku run rake db:migrate