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#’