Intro to Rails Flashcards

1
Q

MVC(Model, View, Controller):

  • The _______ way to create user-interactive applications
  • Created in 1979 by Trygve Reenskaug
A
  • The default way to create user-interactive applications
  • Created in 1979 by Trygve Reenskaug
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does the model do?

–Keeps track of ____ (session and longer)

–________, often via _________

–Enforces _________

A

–Keeps track of state (session and longer)

Persistence, often via database

–Enforces consistency

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

What does View do?

•View ________ user interface

–Based on data in ______

–May look _______ based on browser, user role, assistive technologies, etc.

A

•View generates user interface

–Based on data in model

–May look different based on browser, user role, assistive technologies, etc.

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

What does Controllers do?

•Controllers _______

–Receives______ from ______

–Interacts with _____

A

•Controllers coordinate

–Receives events from view

–Interacts with model

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

MVC Picture:

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

•DB shouldn’t worry about how data are ________

–________ technology can change without affecting any other part of app

–Can add ______ , etc.

A

•DB shouldn’t worry about how data are displayed

Display technology can change without affecting any other part of app

–Can add JavaScript, etc.

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

What is an important concept in MVC?

separation of _______

A

Important concept: separation of concerns

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

Business logic in only ___ _____

A

•Business logic in only one place

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

Separation of Concerns:

  • Code/text only __________ one aspect of app
  • Easier to ____, ______, ______, _______
  • Rails essentially enforces ___
A
  • Code/text only addresses one aspect of app
  • Easier to write, maintain, document, debug
  • Rails essentially enforces MVC
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Rails concepts: Continuous Integration (CI)?
is a development practice that requires developers to ________ code into a shared _________ several times a day. Each check-in is then verified by an __________ build, allowing teams to detect problems early.

A

is a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is then verified by an automated build, allowing teams to detect problems early.

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

Rails concepts: Extreme programming (XP)

is a software development _________ which is intended to improve software quality and _____________to changing customer requirements.

A

is a software development methodology which is intended to improve software quality and responsiveness to changing customer requirements.

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

Rails conepts: Kanban

is a ______ to control the ______ chain from a production point of view, and is an ___________ control system. Kanban was developed by Taiichi Ohno, an industrial engineer at Toyota, as a system to improve and maintain a high level of production. Kanban is one method to achieve ___.

A

is a system to control the logistical chain from a production point of view, and is an inventory control system. Kanban was developed by Taiichi Ohno, an industrial engineer at Toyota, as a system to improve and maintain a high level of production. Kanban is one method to achieve JIT.

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

Rails concepts: just-in-time (JIT) compilation:

also known as dynamic __________, is _________ done during execution of a program – __ ___ ____ – rather than prior to execution

A

also known as dynamic translation, is compilation done during execution of a program – at run time – rather than prior to execution.

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

Rails Concepts: Scrum:

is an ______ and __________ agile software development ____________ for managing product development.

A

is an iterative and incremental agile software development methodology for managing product development.

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

Rails concepts: Test-driven development (TDD)

is a software development process that relies on the ________ of a very short development cycle: first the developer ______ an (initially failing) automated test case that defines a desired _________or new _____, then produces the minimum amount of code to pass that test, and finally _______the new code to ________ standards.

A

is a software development process that relies on the repetition of a very short development cycle: first the developer writes an (initially failing) automated test case that defines a desired improvement or new function, then produces the minimum amount of code to pass that test, and finally refactors the new code to acceptable standards.

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

Rails conventions: Requests are sent to a _______

–Sends request to an action in a _______

A

•Requests are sent to a router

–Sends request to an action in a controller

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

Rails conventions: •HTTP requests: ___, ____, ___, ______

A

HTTP requests: GET, POST, PUT, DELETE

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

Rails Concepts: Convention over configuration:

–Directory ________ mirrors MVC

–Don’t have to change _____ files much, if at all
•Don’t Repeat Yourself

•Agile

A

–Directory structure mirrors MVC

–Don’t have to change config files much, if at all
•Don’t Repeat Yourself

•Agile

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

Model Conventions: OO programming languages are designed around ______

A

•OO programming languages are designed around objects

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

Rails conventions: Router usually treats first part of _____ as the controller name:

A

•Router usually treats first part of path as the controller name

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

Model Conventions: Databases are designed around ______, ____, and ______

A

•Databases are designed around tables, rows, and columns

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

Rails conventions: •If action is _____, calls “create” method for that controller, via naming conventions

A

•If action is POST, calls “create” method for that controller, via naming conventions

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

ORM:Classes become ______

A

Classes become tables

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

ORM:Values in those objects become _______

A

Values in those objects become columns

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
ORM: Objects become ____ in those \_\_\_\_\_
Objects become **rows** in those **tables**
26
**Model Naming Conventions:** ______ are singular and table is \_\_\_
•**Classes** are singular and table is **pural**
27
**Model Conventions:** •How can we save objects in a \_\_?
•How can we save objects in a **DB**?
28
**ORM:** Object-\_\_\_\_\_\_ ______ (ORM) is a technique (a.k.a. design pattern) of accessing a relational ________ from an \_\_\_\_\_\_-\_\_\_\_\_\_\_ language (Java, for example)
Object-relational mapping (ORM) is a technique (a.k.a. design pattern) of accessing a relational database from an object-oriented language (Java, for example)
29
**ORM:** Rails has ActiveRecord to do this, and much more - \_\_\_, \_\_\_\_\_\_, \_\_\_\_, \_\_\_\_\_\_, etc.
•Rails has ActiveRecord to do this, and much more –Add, delete, find, modify, etc.
30
**ORM:** Upside: stay within ____ and \_\_\_\_\_, no SQL
•Upside: stay within **Ruby** and **Rails**, no SQL
31
Views: Rails has XML \_\_\_\_
•XML **builder**
32
**ORM Continued:** * Class ______ perform\_\_\_\_\_\_\_\_ operations * Instance _______ perform ______ operations
* Class **methods** perform **table-level** operations * Instance **methods** perform **row-level** operations
33
**Views:** •ERb templates –Allows ________ of Ruby in a document –Somewhat violates __________ of concerns
•ERb templates –Allows **embedding** of Ruby in a document –Somewhat violates **separation** of concerns
34
**Controllers:** •ActionPack contains ______ for ____ and \_\_\_\_\_\_
•ActionPack contains **methods** for **views** and **controllers**
35
Controllers: _______ sessions
**Manages** sessions
36
Controllers: Manages \_\_\_\_\_\_\_
•Manages **caching**
37
Controllers: Responsible for \_\_\_\_\_\_\_
Responsible for **routing**
38
**CamelCase:** CamelCase (also camel caps or medial capitals) is the practice of writing compound _____ or ________ such that each _____ or \_\_\_\_\_\_begins with a ______ letter.
CamelCase (also camel caps or medial capitals) is the practice of writing compound **words** or **phrases** such that each **word** or **abbreviation** begins with a **capital** letter.
39
**Naming Conventions:** ## Footnote •One major part of conventions is \_\_\_\_\_\_ –In most applications, _____ are meaningless to the \_\_\_\_\_ –In \_\_\_\_\_, ____ drive much of the \_\_\_\_\_\_ * Creating a ____ for a Person creates a _____ table people * Variables ________ and \_\_\_\_\_\_\_\_ * \_\_\_\_\_\_are CamelCased
•One major part of conventions is naming –In most applications, names are meaningless to the software –In Rails, names drive much of the functionality * Creating a model for a Person creates a database table people * Variables lowercase and underscores * Classes are CamelCased
40
**Naming Conventions Continued:** •DB table names “\_\_\_ \_\_\_\_” class names –Always \_\_\_\_ * With ______ and \_\_\_\_\_\_\_\_\_\_ * Class Student –DB table \_\_\_\_\_\_\_ –app/models/students.rb
•DB table names “look like” class names –Always plural * With lowercase and underscores * Class Student –DB table students –app/models/students.rb
41
**Naming Conventions Continued Controllers:**•Controllers –StudentController –app/controllers/student\_controller.rb –http://…/student/list * Calls ___ method in student\_controller.rb * Subdirectories add to \_\_\_\_ –View _______ in app/views/student –Layout _______ app/views/layouts/application.html.erb and .xml
•Controllers –StudentController –app/controllers/student\_controller.rb –http://…/student/list * Calls list method in student\_controller.rb * Subdirectories add to path –View templates in app/views/student –Layout templates app/views/layouts/application.html.erb and .xml
42
**New:** ## Footnote $ rails ___ demo create create README.rdoc create Rakefile … Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed. Post-install message from rdoc: Depending on your version of ruby, you may need to install ruby rdoc/ri data: \<= 1.8.6 : unsupported = 1.8.7 : gem install rdoc-data; rdoc-data --install = 1.9.1 : gem install rdoc-data; rdoc-data --install \>= 1.9.2 : nothing to do! Yay!
$ rails **new** demo create create README.rdoc create Rakefile … Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed. Post-install message from rdoc: Depending on your version of ruby, you may need to install ruby rdoc/ri data: \<= 1.8.6 : unsupported = 1.8.7 : gem install rdoc-data; rdoc-data --install = 1.9.1 : gem install rdoc-data; rdoc-data --install \>= 1.9.2 : nothing to do! Yay!
43
**“Conventions”:** •create config/routes.rb –Message à method \_\_\_\_\_\_\_ –See via “\_\_\_ \_\_\_\_\_” •create config/\_\_\_\_\_\_\_\_.rb –Timezone, locale, encodings, preloads, etc. * create config/environment.rb * create config/environments
•create config/routes.rb –Message à method mapping –See via “rake routes” •create config/application.rb –Timezone, locale, encodings, preloads, etc. * create config/environment.rb * create config/environments
44
**Three Modes:** ## Footnote * rails server –e development * create config/environments/development.rb –No \_\_\_\_\_\_, etc. * create config/environments/production.rb * create config/environments/test.rb •
* rails server –e development * create config/environments/development.rb –No **caching**, etc. * create config/environments/production.rb * create config/environments/test.rb •
45
**“Conventions” Continued** ## Footnote * create config/locales * create config/locales/en.yml * create config/boot.rb * create config/database.yml –Which DB to ___ and how to \_\_\_\_\_\_
* create config/locales * create config/locales/en.yml * create config/boot.rb * create config/database.yml –Which DB to **use** and how to **connect**
46
**Default Messages:** ## Footnote * create public/404.html * create public/422.html * create public/500.html * create public/favicon.ico * create public/index.html * create public/robots.txt
* create public/404.html * create public/422.html * create public/500.html * create public/favicon.ico * create public/index.html * create public/robots.txt
47
**Default Tests** ## Footnote * create test/fixtures * create test/functional * create test/integration * create test/unit * create test/performance/browsing\_test.rb * create test/test\_helper.rb
* create test/fixtures * create test/functional * create test/integration * create test/unit * create test/performance/browsing\_test.rb * create test/test\_helper.rb
48
**App:** ## Footnote •\_\_\_/controllers: –application\_controller.rb •app/\_\_\_\_: –application\_helper.rb * app/\_\_\_\_\_\_ * app/models * app/views/layouts: –\_\_\_\_\_\_\_\_\_.html.erb
•**app**/controllers: –application\_controller.rb •app/**helpers**: –application\_helper.rb * app/**mailers** * app/models * app/views/layouts: –**application**.html.erb
49
Aside: Errorr: ## Footnote $ rails generate ______ Student studentname:string studentid:integer \_\_\_\_\_\_ active\_record The name 'Student' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative and run this generator again.
$ rails generate **scaffold** Student studentname:string studentid:integer **invoke** active\_record The name 'Student' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative and run this generator again.
50
**Scaffolding:** A scaffold in Rails is a full __ \_\_ \_\_\_\_\_, __________ migration for that \_\_\_\_\_, controller to manipulate it, _____ to view and manipulate the data, and a ____ \_\_\_\_\_ for each of the above.
•A scaffold in Rails is a full **set of model**, **database** migration for that **model**, controller to manipulate it, **views** to view and manipulate the data, and a **test suite** for each of the above.
51
**Types:** ## Footnote * :datetime * :timestamp * :time * :date * :binary * :boolean -------------------------- * :primary\_key * :string * :text (short strings) * :integer * :float * :decimal (fixed precision, currency)
* :datetime * :timestamp * :time * :date * :binary * :boolean -------------------------- * :primary\_key * :string * :text (short strings) * :integer * :float * :decimal (fixed precision, currency)
52
**Create a Student:** ## Footnote $ rails new demo $ cd demo $ rails generate _____ Student studentname:string studentid:integer
$ rails new demo $ cd demo $ rails generate **scaffold** Student studentname:string studentid:integer
53
**Migration:** ## Footnote class CreateStudents \< \_\_\_\_\_\_\_\_\_\_\_\_::\_\_\_\_\_\_ def change create\_table :students do |t| t. \_\_\_\_\_ :studentname t. \_\_\_\_\_\_:studentid \_.timestamps null: false end end end
class CreateStudents \< **ActiveRecord**::**Migration** def change create\_table :students do |t| t. **string** :studentname t. **integer** :studentid **t**.timestamps null: false end end end
54
**Aside: Errorr:** ## Footnote $ rails ___ Student create create README.rdoc create Rakefile create config.ru create .gitignore create Gemfile […]
$ rails **new** Student create create README.rdoc create Rakefile create config.ru create .gitignore create Gemfile […]
55
rake db:migrate ## Footnote $ rake db:migrate == CreateStudents:\_\_\_\_\_\_\_\_ ================================================= -- create\_table(:students) -\> 0.0014s == CreateStudents: migrated (0.0015s) ========================================
$ rake db:migrate == CreateStudents: **migrating** ================================================= -- create\_table(:students) -\> 0.0014s == CreateStudents: migrated (0.0015s) ========================================
56
**If you don't like it:** $ rails destroy\_\_\_\_\_\_ Student
$ rails destroy **scaffold** Student
57
**If you really don't like it:** ## Footnote $ spring \_\_\_ $ cd .. $ rm –rf college
$ spring **stop** $ cd .. $ rm –rf college
58
**rake routes:** students GET /students(.:format) students#index POST /students(.:format) students#create new\_student GET /students/new(.:format) students#new edit\_student GET /students/:id/edit(.:format) students#edit student GET /students/:id(.:format) students#show PUT /students/:id(.:format) students#update DELETE /students/:id(.:format) students#destroy
students GET /students(.:format) students#index POST /students(.:format) students#create new\_student GET /students/new(.:format) students#new edit\_student GET /students/:id/edit(.:format) students#edit student GET /students/:id(.:format) students#show PUT /students/:id(.:format) students#update DELETE /students/:id(.:format) students#destroy
59
**The Entire Model** $ more app/models/student.rb class Student \< ActiveRecord::Base attr\_\_\_\_\_\_\_ :id, :name end
$ more app/models/student.rb class Student \< ActiveRecord::Base attr\_accessible :id, :name end
60
**Controller: Find All** class StudentsController \< \_\_\_\_\_\_\_\_\_\_ GET /students GET /students.json def index @students = Student.all respond\_to do |format| format. html # _____ .html.erb format. json { render json: @students } end end
class StudentsController \< **ApplicationController** GET /students GET /students.json def index @students = Student.all respond\_to do |format| format. html # **index**.html.erb format. json { render json: @students } end end
61
**Controller: Find One** GET /students/1 GET /students/1.json def show @student = Student. \_\_\_(params[:id]) \_\_\_\_\_\_\_ do |format| format. html # ____ .html.erb format. json { render json: @student } end end •
GET /students/1 GET /students/1.json def show @student = Student.**find**(params[:id]) **respond\_to** do |format| format. html # **show**.html.erb format. json { render json: @student } end end •
62
**Controller: New** GET /students/new GET /students/new.json def new @student = Student. \_\_\_ respond\_to do |format| format. html # new.html.erb format. json { render json: @student } end end
GET /students/new GET /students/new.json def new @student = Student.**new** respond\_to do |format| format. html # new.html.erb format. json { render json: @student } end end
63
**Controller: Edit** GET /students/1/edit def \_\_\_\_ @student = Student.find(params[:id]) end automagically calls app/views/students/edit.html.erb
GET /students/1/edit def **edit** @student = Student.find(params[:id]) end automagically calls app/views/students/edit.html.erb
64
**Controller: Create** POST /students POST /students.json def create @student = Student.\_\_\_(params[:student]) respond\_to do |format| if @student.\_\_\_\_ format. html { redirect\_to @student, notice: 'Student was successfully created.' } format. json { render json: @student, status: :created, location: @student } else format. html { render action: "new" } format. json { render json: @student.errors, status: :unprocessable\_entity } end end end
POST /students POST /students.json def create @student = Student.**new**(params[:student]) respond\_to do |format| if @student.**save** format. html { redirect\_to @student, notice: 'Student was successfully created.' } format. json { render json: @student, status: :created, location: @student } else format. html { render action: "new" } format. json { render json: @student.errors, status: :unprocessable\_entity } end end end
65
**Controller: Update:** ## Footnote PUT /students/1 PUT /students/1.json def \_\_\_\_\_ @student = Student.find(params[:id]) respond\_to do |format| if @student.update\_attributes(params[:student]) format. html { redirect\_to @student, notice: 'Student was successfully updated.' } format. json { head :no\_content } else format. html { render action: "edit" } format. json { render json: @student.errors, status: :unprocessable\_entity } end end end
PUT /students/1 PUT /students/1.json def **update** @student = Student.find(params[:id]) respond\_to do |format| if @student.update\_attributes(params[:student]) format. html { redirect\_to @student, notice: 'Student was successfully updated.' } format. json { head :no\_content } else format. html { render action: "edit" } format. json { render json: @student.errors, status: :unprocessable\_entity } end end end
66
**Controller: Delete/Destroy** DELETE /students/1 DELETE /students/1.json def \_\_\_\_\_\_\_ @student = Student.find(params[:id]) @student.destroy respond\_to do |format| format. html { redirect\_to students\_url } format. json { head :no\_content } end end end
DELETE /students/1 DELETE /students/1.json def destroy @student = Student.find(params[:id]) @student.destroy respond\_to do |format| format. html { redirect\_to students\_url } format. json { head :no\_content } end end end
67
**View: Index**
Name Id
68
**View: Index Continued**
69
**Partial:**
70
**Partial Continued:**
71
**View: New**
72
**View: Edit**
73
**Model Naming Conventions:** Classes are _____ \_\_\_\_\_\_ , Rails turns them into _____ \_\_\_\_\_\_ and \_\_\_\_\_\_\_\_
•Classes are **camel cased**, Rails turns them into **lower cased** and **underscored**
74
**Model Naming Conventions:** ## Footnote •Classes are camel cased, Rails turns them into ____ \_\_\_\_\_ and \_\_\_\_\_\_\_\_\_\_\_\_\_\_ –Class StudentEmployee creates a table student\_employees
•Classes are camel cased, Rails turns them into lower cased and underscored –Class StudentEmployee creates a table student\_employees
75
**Controller Naming Convention** ## Footnote •If there is a ClassScheduler \_\_\_\_\_\_\_\_\_\_\_ –Creates app/controllers/class\_scheduler.rb
•If there is a ClassScheduler controller –Creates app/controllers/class\_scheduler.rb
76
**View Naming Convention:** * app/helpers/class\_scheduler.rb * ERb _________ in app/view/class\_scheduler
* app/helpers/class\_scheduler.rb * ERb templates in app/view/class\_scheduler
77
**Route Naming:** If a _______ arrives for “admin/book”, _____ looks for a book\_controller.rb in app/controllers/admin
•If a **request** arrives for “admin/book”, **Rails** looks for a book\_controller.rb in app/controllers/admin
78
**ActiveRecord Automatic Additions:** •id – default primary key –Can \_\_\_\_\_\_, but still reference via “id
•id – default primary key –Can override, but still reference via “id
79
**ActiveRecord Automatic Additions:** •x\_id – _______ key for a table named x
•x\_id – foreign key for a table named x
80
**ActiveRecord Automatic Additions:** ## Footnote •created\_at, created\_on, updated\_at, updated\_on –\_at have a \_\_\_\_\_\_
•created\_at, created\_on, updated\_at, updated\_on –\_at have a time