Ruby Flashcards
3 principles underlying Ruby mechanisms:
1- Everything is an object
2- Every operation is a method call on some object and returns a value
3- All programming is metaprogramming
What is metaprogramming?
Classes and methods can be added or changed at any time, even while a program is running
Is Ruby interpreted or compiled?
Compiled
migrations
-
routing
-
embedded Ruby
-
What kind of a site is Twitter
social media microblogging site
What is the built-in testing site in Ruby?
Mini Test
External dependencies (add-ins)
- RSpec
- Cucumber
- Capybara
- Factory Girl
mockups
-
what is Ruby scaffolding?
- automatically creates code to model data and interact with it through the web
- scaffolding is good for getting started quickly
- not good for understanding
URI
-Uniform Resource Identifier
URL
-Uniform resource locator
What is Ruby on Rails
- 100% open source
- available under MIT license
- a domain specific language for writing web applications
- makes common web programming tasks - such as generating HTML, making data models, routing URLs -easy
- adapts rapidly to new developments in web technology and frameworks
- first framework to fully digest REST
gem
-self-contained solutions to specific problems such as pagination and image uploade
the default Rails testing framework
MiniTest
Ruby books
- Learn to Program by Chris Pine
- Beginning Ruby by Peter Cooper
- Learn Ruby on Rails by Daniel Kehoe
Resources for intermediate to advanced Ruby
- Code School
- The Turing School of Software & Design (Denver)
- Tealeaf Academy (online)
- Thinkful
- Pragmatic Studio: Online Ruby and Rails courses
- RailsCasts by Ryan Bates
- RailsApps
- Rails guides
- http://www.railstutorial.org/#help
- [Bk] Conquering the Command Line by Mark Bates
website for “how to install rails”
InstallRails.com
RubyGems
-
3 essential components needed to install web applications
1-a text editor
2-a file system navigator
3-a command-line terminal
a global search that is essential to navigating any large Roby or Rails project
“Find in Files” global search
universal indentation convention in Rugy
-using two spaces for indenting
How do you create a new Rails application?
- rails new
- creates a skeleton rails application in whatever directory you are in
command line
-one of the most powerful tools in the developer’s toolbox
What does “rails new” do?
- Creates the standard directory and file structure common to all Rails apps
- automatically runs the bundle install command after the file creation is done
How do you change the default application gems?
-Open the Gemfile with a text editor
gem: uglifier
handles file compression for the asset pipeline
What command do you use to install only the latest gem
> =
-see Ruby tutorial p. 20
how do you install gems?
- Update the Gemfile with the gems you want to use
- $ bundle install
How does Cloud9 assign the IP address and port number dynamically to run a web server?
-using the special environment variables $IP and $PORT
$ rails server -b $IP -p $PORT
How do you generate a rails scaffolding?
-pass the scaffold command to the rails generate script
-the argument of the scaffold command is the singular version of the resource name (ex. User) along with optional parameters for the data model’s attributes
$ rails generate scaffold User name:string email:string
-id does not have to be added. It is created automatically by Rails for use as the primary key in the database.
tutorial p. 56
What is Rake?
-the Ruby version of Make
-a make-like language written in Ruby
-
How do you migrate the database using Rake?
$ bundle exec rake db:migrate
- updates the database with our new Users data model.
- we run Rake using bundle exec to ensure that the command user the version of Rake corresponding to our Gemfile.
REST
- Representational State Transfer
- an architectural style
- most application components are modeled as resources that can be created, read, updated, and deleted
- corresponding to the HTTP request methods: Post, Get, Patch, Delete
- helps you make choices about which controllers and actions to write by structuring the application using resources that get created, read, updated, and deleted
instance variables
- start with @
- these variables are automatically available in the views
console
-useful tool for interacting with Rails applications
$ rails console
The base class for controllers provided by the Rails library Action PackA
- ActionController::Base
- ApplicationController inherits from ActionController::Base
- All Rails controllers inherit from ApplicationController
Patch
- used for data updates
- used to be “push”
Controller action
-defined inside controllers
How do you see a list of current controllers?
$ ls app/controllers/*_controller.rb
root route
- determines the page that is served on the root URL
- because the root URL is the URL for an address where nothing comes after the final slash, it is often referred to as “slash”
- you can structure the root route with the command root in the routes.rb file in the config directory
- root ‘application#hello’ tells it to go to the hello controller action in the controller called application
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 URL
-referred to as slash because nothing comes after the slash
How do you tell the application where to route the root?
use the root command with the controller name followed by # and then the action within that controller
$ root ‘welcome#index
resource
a combination of the data model and the user interface to update it
-tutorial p. ?
How do you generate rails scaffolding?
Pass the scaffold command to the rails generate script.
What are the arguments of the scaffold command?
The singular version of the resource name (such as ‘user’) together with optional parameters for the data model’s attributes
naming convention for models and controllers
- models are singular (such as “user”)
- resources and controllers are plural
what is the primary key in a rails table?
-id (which is created automatically by rails)
what is meant by “migrate” the database and how is it done?
-update the database with a new model
-it is done using rake
$ bundle exec rake db:migrate
Rake is run using bundle exec in order to ensure that the command uses the version of Rake corresponding to our gemfile
How do you run the rails server?
$ rails server -b $IP -P $PORT
use only “rails server” if running locally
What is the console? and how do you invoke it?
-a useful tool for interacting with rails apps
$ rails console
> > exit
to exit the console
or CNTRL-d
What is the base class for models provided by Active Record?
ActiveRecord::Base
our model objects inherit from ActiveRecord::Base to gain the ability to communicate with the database, treat the database columns as Ruby attributes, etc
How do you search file names?
GoTo Anything command
what does
$ rails server
do?
a Rails command-line program (or script)
that runs a local web server to assist in application development
for cloud 9 us
$ rails server -b $IP -p $PORT
What is the root route?
It is the default action that is invoked by the root URL (or slash)
what is the format for a route?
controllerName#controllerActionName
ex: root ‘application#index’
where the controller is “welcome” and the action is “index”