Chapter 1 (with some of Chapter 6) Flashcards

1
Q

How do you create a new gemset in rvm?

A

Example syntax:

$ rvm use ruby-2.1.5@rails4.2 –create

Once in the gemset, be sure to install rails!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Who created Rails and when?

A

David Heinemeier Hansson in 2004

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the command to create a local development server?

A

$ rails server

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the first step in designing a new rails app?

A

Go to your workspace, and run the ‘rails new ‘ command

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the purpose of each folder generated by ‘rails new’?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does ‘bundle install’ do?

A

It installs and includes the gems needed by the app according to the Gemfile

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

T/F: ‘bundle install’ is not run at the end of ‘rails new’

A

F; it is

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How can we specify ranges in the Gemfile, and why might we do this?

A

’>=’ 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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

If we change our Gemfile, how can we update the app to reflect the changes?

A

run ‘$ bundle install’ or, if that fails, ‘$ bundle update’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How can we see our app running on the rails server?

A

Point your browser to the url given by the server (usually localhost:3000)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the MVC architectural pattern?

A

The “model-view-controller” architectural pattern, which separates “domain logic” from the GUI (input and presentation logic)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is “domain logic”? What does the GUI refer to?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Articulate the process of how a rails app interacts with a web browser? What is the difference between a view and a model?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Where can we find controllers, and what are they for?

A

In the app/controllers directory. They are used for defining controller actions, which is part of what the webpage does.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

When defining a controller action (function), what function must be included to return text?

A

‘render text: “”’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Where can we change where to send browser requests? Why is this important?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How do we create a new Git repo?

A

Navigate to the root directory of the project and run ‘$ git init’

18
Q

What is the command to add all files to the repo?

A

$ git add -A

19
Q

What does ‘$ git status’ do, and how does it relate to the ‘add’ command?

A

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

20
Q

How do we confirm changes with Git?

A

’$ git commit -m “”’

21
Q

How do we revert to the last commit?

A

$ git checkout -f

22
Q

What is the first step in making a new BitBucket repo?

A

Create a new private Git repo with a name matching your root directory

23
Q

What is the command to connect to your repo?

A

$ git remote add origin git@bitbucket.org:/.git

24
Q

How do we create a new branch?

A

$ git checkout -b `

25
Q

With the ‘$ git branch’ command, what does the ‘*’ in the results indicate?

A

The current branch

26
Q

What is the syntax for the first time we push up to our repo?

A

$ git push -u origin –all

27
Q

What do the -a and -m flags do in the commit command?

A

-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).

28
Q

What does ‘git checkout branch’ do?

A

Switches the active branch.

29
Q

How do we merge the changes of one test branch to the master branch?

A

$ git merge

MUST BE IN MASTER BRANCH!

30
Q

What is the cleanest thing to do once you’ve finished merging a branch?

A

Delete the branch with ‘$ git branch -d ‘

31
Q

What needs to be added to the Gemfile in order to use Heroku?

A

group :production do
gem ‘pg’, ‘0.17.1’
gem ‘rails_12factor’, ‘0.0.2’
end

32
Q

How do we add out commit to BitBucket?

A

$ git push

33
Q

What is the point of the following command?

$ bundle install –without production

A

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.

34
Q

How do we create space for a new application on Heroku?

A

$ heroku create

35
Q

How do we deploy to Heroku?

A

$ git push heroku master

36
Q

What is the command to change the name of our Heroku deployment, and what will the resulting address be?

A

$ heroku rename newname.herokuapp.com

37
Q

How can we view our live site directly from the command line?

A

$ heroku open

38
Q

Why is storing hashed values instead of passwords advantageous?

A

If a database is compromised, user passwords will still be secure.

39
Q

What does #has_secure_password do, and what does it require to work?

A

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.

40
Q

T/F: The following code is valid:

@user.password = @user.password_confirmation = “a” * 5

A

T; it is a case of compact multiple assignment

41
Q

What is a last step when deploying to heroku?

A

$ heroku run rake db:migrate