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
Q

ORM: Objects become ____ in those _____

A

Objects become rows in those tables

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

Model Naming Conventions: ______ are singular and table is ___

A

Classes are singular and table is pural

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

Model Conventions: •How can we save objects in a __?

A

•How can we save objects in a DB?

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

ORM:

Object-______ ______ (ORM) is a technique (a.k.a. design pattern) of accessing a relational ________ from an ______-_______ language (Java, for example)

A

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)

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

ORM: Rails has ActiveRecord to do this, and much more

  • ___, ______, ____, ______, etc.
A

•Rails has ActiveRecord to do this, and much more

–Add, delete, find, modify, etc.

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

ORM: Upside: stay within ____ and _____, no SQL

A

•Upside: stay within Ruby and Rails, no SQL

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

Views: Rails has XML ____

A

•XML builder

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

ORM Continued:

  • Class ______ perform________ operations
  • Instance _______ perform ______ operations
A
  • Class methods perform table-level operations
  • Instance methods perform row-level operations
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

Views: •ERb templates
–Allows ________ of Ruby in a document
–Somewhat violates __________ of concerns

A

•ERb templates

–Allows embedding of Ruby in a document

–Somewhat violates separation of concerns

34
Q

Controllers:

•ActionPack contains ______ for ____ and ______

A

•ActionPack contains methods for views and controllers

35
Q

Controllers: _______ sessions

A

Manages sessions

36
Q

Controllers: Manages _______

A

•Manages caching

37
Q

Controllers: Responsible for _______

A

Responsible for routing

38
Q

CamelCase: CamelCase (also camel caps or medial capitals) is the practice of writing compound _____ or ________ such that each _____ or ______begins with a ______ letter.

A

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
Q

Naming Conventions:

•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
A

•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
Q

Naming Conventions Continued:

•DB table names “___ ____” class names

–Always ____

  • With ______ and __________
  • Class Student

–DB table _______

–app/models/students.rb

A

•DB table names “look like” class names

–Always plural

  • With lowercase and underscores
  • Class Student

–DB table students

–app/models/students.rb

41
Q

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

A

•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
Q

New:

$ 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!

A

$ 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
Q

“Conventions”:

•create config/routes.rb

–Message à method _______

–See via “___ _____”

•create config/________.rb

–Timezone, locale, encodings, preloads, etc.

  • create config/environment.rb
  • create config/environments
A

•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
Q

Three Modes:

  • rails server –e development
  • create config/environments/development.rb

–No ______, etc.

  • create config/environments/production.rb
  • create config/environments/test.rb

A
  • rails server –e development
  • create config/environments/development.rb

–No caching, etc.

  • create config/environments/production.rb
  • create config/environments/test.rb

45
Q

“Conventions” Continued

  • create config/locales
  • create config/locales/en.yml
  • create config/boot.rb
  • create config/database.yml

–Which DB to ___ and how to ______

A
  • 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
Q

Default Messages:

  • create public/404.html
  • create public/422.html
  • create public/500.html
  • create public/favicon.ico
  • create public/index.html
  • create public/robots.txt
A
  • 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
Q

Default Tests

  • create test/fixtures
  • create test/functional
  • create test/integration
  • create test/unit
  • create test/performance/browsing_test.rb
  • create test/test_helper.rb
A
  • create test/fixtures
  • create test/functional
  • create test/integration
  • create test/unit
  • create test/performance/browsing_test.rb
  • create test/test_helper.rb
48
Q

App:

•___/controllers:

–application_controller.rb

•app/____:

–application_helper.rb

  • app/______
  • app/models
  • app/views/layouts:

–_________.html.erb

A

app/controllers:

–application_controller.rb

•app/helpers:

–application_helper.rb

  • app/mailers
  • app/models
  • app/views/layouts:

application.html.erb

49
Q

Aside: Errorr:

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

A

$ 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
Q

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

•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
Q

Types:

  • :datetime
  • :timestamp
  • :time
  • :date
  • :binary
  • :boolean

  • :primary_key
  • :string
  • :text (short strings)
  • :integer
  • :float
  • :decimal (fixed precision, currency)
A
  • :datetime
  • :timestamp
  • :time
  • :date
  • :binary
  • :boolean
  • :primary_key
  • :string
  • :text (short strings)
  • :integer
  • :float
  • :decimal (fixed precision, currency)
52
Q

Create a Student:

$ rails new demo

$ cd demo

$ rails generate _____ Student studentname:string studentid:integer

A

$ rails new demo

$ cd demo

$ rails generate scaffold Student studentname:string studentid:integer

53
Q

Migration:

class CreateStudents < ____________::______

def change

create_table :students do |t|

t. _____ :studentname
t. ______:studentid

_.timestamps null: false

end

end

end

A

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
Q

Aside: Errorr:

$ rails ___ Student

create

create README.rdoc

create Rakefile

create config.ru

create .gitignore

create Gemfile

[…]

A

$ rails new Student

create

create README.rdoc

create Rakefile

create config.ru

create .gitignore

create Gemfile

[…]

55
Q

rake db:migrate

$ rake db:migrate

== CreateStudents:________

=================================================

– create_table(:students)

-> 0.0014s

== CreateStudents: migrated (0.0015s) ========================================

A

$ rake db:migrate

== CreateStudents: migrating =================================================

– create_table(:students)

-> 0.0014s

== CreateStudents: migrated (0.0015s) ========================================

56
Q

If you don’t like it:

$ rails destroy______ Student

A

$ rails destroy scaffold Student

57
Q

If you really don’t like it:

$ spring ___

$ cd ..

$ rm –rf college

A

$ spring stop

$ cd ..

$ rm –rf college

58
Q

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

A

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
Q

The Entire Model
$ more app/models/student.rb

class Student < ActiveRecord::Base

attr_______ :id, :name

end

A

$ more app/models/student.rb

class Student < ActiveRecord::Base

attr_accessible :id, :name

end

60
Q

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

A

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
Q

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

A

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
Q

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

A

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
Q

Controller: Edit

GET /students/1/edit

def ____

@student = Student.find(params[:id])

end

automagically calls app/views/students/edit.html.erb

A

GET /students/1/edit

def edit

@student = Student.find(params[:id])

end

automagically calls app/views/students/edit.html.erb

64
Q

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

A

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
Q

Controller: Update:

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

A

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
Q

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

A

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
Q

View: Index

A

Name Id

68
Q

View: Index Continued

A
69
Q

Partial:

A
70
Q

Partial Continued:

A
71
Q

View: New

A
72
Q

View: Edit

A
73
Q

Model Naming Conventions: Classes are _____ ______ , Rails turns them into _____ ______ and ________

A

•Classes are camel cased, Rails turns them into lower cased and underscored

74
Q

Model Naming Conventions:

•Classes are camel cased, Rails turns them into ____ _____ and ______________

–Class StudentEmployee creates a table student_employees

A

•Classes are camel cased, Rails turns them into lower cased and underscored

–Class StudentEmployee creates a table student_employees

75
Q

Controller Naming Convention

•If there is a ClassScheduler ___________

–Creates app/controllers/class_scheduler.rb

A

•If there is a ClassScheduler controller

–Creates app/controllers/class_scheduler.rb

76
Q

View Naming Convention:

  • app/helpers/class_scheduler.rb
  • ERb _________ in app/view/class_scheduler
A
  • app/helpers/class_scheduler.rb
  • ERb templates in app/view/class_scheduler
77
Q

Route Naming: If a _______ arrives for “admin/book”, _____ looks for a book_controller.rb in app/controllers/admin

A

•If a request arrives for “admin/book”, Rails looks for a book_controller.rb in app/controllers/admin

78
Q

ActiveRecord Automatic Additions:

•id – default primary key

–Can ______, but still reference via “id

A

•id – default primary key

–Can override, but still reference via “id

79
Q

ActiveRecord Automatic Additions:

•x_id – _______ key for a table named x

A

•x_id – foreign key for a table named x

80
Q

ActiveRecord Automatic Additions:

•created_at, created_on, updated_at, updated_on

–_at have a ______

A

•created_at, created_on, updated_at, updated_on

–_at have a time