ROR 4 essential training Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

what is rails

A

opensource web app framework

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

what is dry (fundamental to rails)

A

dont repeat yourself

provides consise consistant code

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

convention over configuration (second fundamental of rails)

A

sensible defaults, only specify unconventional aspects

this increases speed bc we have default code to rely on and less code to maintain

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

model

A

data objects (like objects in database)

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

view

A

basically what you see (html, css, etc)

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

controller

A

makes decisions and controls aoo based on interaction

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

what does rails call the controller

A

ActionController

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

What does rails call the view

A

ActionView

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

what does rails call the model

A

ActiveRecord

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

what is ActionPack

A

the controller and view packaged together as one thing (ActionController and ActionView)

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

update rubygems

A

gem update –system

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

bundler gem helps how

A

installs all the gems for a particular rails aplication/environment (different versions for different applications, etc)

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

list installed gems

A

gem –list

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

install a gem (and flags to not install ri or rdoc, and specify version)

A

gem install x –no-ri –no-rdoc –version 4.0.0

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

what web servers does rails run by default

A

webrick

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

for deployment rails should be hosted on another server such as

A

apache,nginx

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

how to create rails project

A

rails new projec_name -d server_type

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

where is the root of the directory of the project

A

project_name/

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

gemfile contains what

A

gems we want to load, and their version/source

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

gemfile.lock contains what

A

all the gems, and what those gems depend on

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

how to install new gems

A

add to gem file then run bundle install

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

how to start rails server

A

rails s

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

default port for webrick

A

3000

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

database.yml

A

located in the config folder, contains configuration for connecting to the database

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

On the first starting of the server what should be modified in database.yml and what else needs to be run to get everything to run succesfully

A

edit username to what you created

run:
rake:db:create:all
rake db:migrate

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

a minimum rails app can run on what three components

A

C,V,browser

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

how to create a controller with view

A

rails generate controller cname vname

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

when generating a controller with a second paramater as a view what happens

A

creates cname_controller.rb in app/controllers

creates index.html.erb in app/views/demo/

creates route get “demo/index” (which is exactly what is put in the route file– also by default if you want to access this page thats what you have to append to the site name)

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

a generated controller has what in it by default if generated by controller and view name of index

A

class cnameController < ApplicationController

def index
end
end

the < denotes that cnameController inherits from ApplicationController

the def index is a simple action that, even though it has nothing in it, it renders a view and uses a layout

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

how to disable a layout from the controller

A

layout false

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

by default a rails view contains what

A

some basic html

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

app directory contains what

A

assets, mvc, helpers, and mailers

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

helpers folder contains what

A

most of the ruby code to support the view

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

mailers folder is for what

A

sending email

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

assets folder is for what

A

images/stylesheets/js

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

bin folder contains what

A

bundle, rails, rake

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

config folder contains

A

configuration for app, be it database.yml, application, or the subfolder environments for (test, production, and development)

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

initializers folder

A

things we need to launch when app launches, like config files

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

config.ru is what

A

the config file for rack that works with rails

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

lib folder

A

assets, tasks>contains tasks that we might write

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

concern about public folder

A

anything in public folder is visible to public (alternate place for images/js/stylesheets)

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

test folder

A

hold the code for TDD like apps

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

tmp folder

A

cookies, sessions, etc

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

vendor folder

A

third party code

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

when a web server requests something, what can intercept it from ever reaching the rails architecture?

A

if its directly in the public folder

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

what does routing do

A

parses url for which controller and action to user

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

three route types

A

simple, default root

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

how does rails routes handle a get request

A

GET “page/subpage”by processing PageController#page as html and then renders template

rails knows how to do this via the route file after generating the controller command

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

simple route

A

get “demo/index”

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

match route (basically the steps in how route works)

A

get “demo/index”

match:”demo/index”,
: to =>”demo#index”,
:via => get

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

if route doesnt find a match what happens

A

rails returns routing error

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

default route structure

A

:controller/:action/:id

ex GET /students/edit/52
says go to StudentsController, end perform edit action on 52

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

default route example

A

match ‘:controller(/:action(/:id))’, :via => :get

very important to add

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

default route allows the absence of what

A

an action, it applies a default using match

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

default route that returns a type of format like json

A

just like default with additional format

match ‘:controller(/:action(/:id(/.:format)))’, :via => :get

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

root route

A

when you go to the root of the application and have nothing to match, this tells it where it should go

root “demo#index”

should be placed at end of routes file due to it processing top to bottom

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

route processed in what order

A

top to bottom

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

in a controller for an action like (def index end) what is the default behavior

A

load index template in demo directory

knows template should be index bc thats the name of the action, and knows its in demo dir because that s the name of the controller

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

is an action required for each template

A

no, but it is good practice (i.e. def index end)

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

how to specify a template for an action

A

render(:template => ‘demo/hello’)

short hand if youre in the same directory you can narrow to just a string i.e. (render(‘hello’)

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

what is a redirect

A

sends request to different controller and action

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

redirect keyword

A

redirect_to(:controller => ‘demo’, :action =>’index’)

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

if redirecting to within same controller, what can be left out in the redirect function

A

the controller

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

does a redirect need to render a layout

A

false

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

can you use redirect_to to redirect to external site?

A

yes, just use url in string

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

how do we embed ruby code into our site

A

ERb (embedded ruby)

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

different parts of hello.html.erb

A

hello:template
process with:erb
output format:html (you could use alts like xml etc)

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

how to embed code in erb

A

’% code %’

also ‘%= code %’

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

difference between
‘% code %’
also ‘%= code %’

A

first executes (any attempted output may be shown in command prompt), second executes then outputs

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

execute a block of code x times

A

‘%x.times do%’
(if you want to out put use:)’%= code %’
‘%end%’

in short you can have a code flow broken up and only have the output in the = part

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

a way to pass data from controller to view

A

instance variables (a variable applies inside this instance of an object, in rails, the controller is the object)

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

is a controller a class?

A

yes view

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

are non instance variables in the controller available to the

A

no

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

link method

A

’%= link_to(text, url) %’

for url you can use regular “/demo/index/”

or you can specifically pass a hash {:controller => ‘demo’, :action => ‘index} (same applies here, where if its in the same demo, you can just pass action)

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

add url paramaters to link (those that start after ? and seperated by &)

A
{ :controller=>'demo',
\:action=>'hello',
\:id=>1,
\:page=>3,
\:name=>kevin}
as always, can leave out controller and action if theres a default

constructs
/demo/hello/1?page=3&name=kevin

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

shorthand for hash if all keys ar symbols

A

hash={font_size:10} vs hash={fontsize =>10}

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

HashWithIndifferenntAccess

A

allows you to access hash keys using symbol or key

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

params

A

returns hash with all paramaters sent in get and post hash

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

params is accesible where

A

view and controller, but should be accessed in controller

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

assign params to an instance var

A

@page= params[:page]

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

why are params useful for getting

A

they are available in the get and post, so if we assign a param to an instance variable we can use it for something specific, however, we can also access param values passed without assigning them to a variable by using params[:id]

82
Q

template error

A

error in rendering template

83
Q

in erb if you cast something to say an integer what happens to it in html

A

html only has string so html will convert the int back to string

84
Q

params.inspect

A

lists hash array of params

85
Q

access permissions are granted here

A

database level

86
Q

1 table is equal to

A

1 model

87
Q

a model and its table can be represented by what part of speach

A

the noun (users, products, orders)

88
Q

tables are always plural and use underscores for space it needed?

A

true because tables consist of many singulars

89
Q

columns are represented by a single simple type

A

email, name, password

90
Q

rows contain what

A

an object or an instance of a model, single record of data (Name: “Kevin”)

91
Q

rails command to create a model

A

rails g scaffold User name:string emaill:string

92
Q

what is .yml

A

YAML—aint no markup language

93
Q

3 rails environments

A

production=live
test=ussed for test code, usually contains test dbs
development=for developing application

(is possible to create more envs)

seperated so you can configure diff things for certain situations like debug code in development

94
Q

rake db:schema:dump

A

creates the schema.rb in config-db

95
Q

rake

A

“ruby make”

96
Q

where can you add your own rake tasks

A

lib/tasks

97
Q

how to put server in production mode

A

rake db:schema:dump RAILS_ENV=production

the dump is just used to set up the schema from dev or w/e else without the data

98
Q

what is a migration

A

set of db instructs that migrate db from one state to another, like moving “up” to a new state or down to a previous

99
Q

can you migrate backwards

A

yes

100
Q

benefits of migrations

A

executable and repeatable to keep db schema and app code, and sharing schema changes to keep in sync

if using versioning can migrate to proper db state

101
Q

Migrations reside where

A

in the db directory

102
Q

how to create a custom migration

A

rails g migration TestName

103
Q

When you create a migration what happens

A

active_record is invoked

a migrate folder is added as a sub to the db dir

simple class created inheriting from ActiveRecord::Migration

creates empty method called change

104
Q

migration names are prefixed with what

A

a timestamp, and the camelcase migration name is changed to lower case with underscores

105
Q

ActiveRecord

A

Active Record facilitates the creation and use of business objects whose data requires persistent storage to a database

106
Q

How could you create a migration that implements methods for change and to unchange

A

two methods: up(changes),down(backwards)

107
Q

how do you create a model

A

rails g model User name:string{30}

108
Q

what happens when you generate a model

A

generates a migration to a connected db, creates the model data(table), place holder for test file

migration file is called create_x(pluralized) – this is because model name is singular but their are plurals within

109
Q

drop a table

A

drop_table :users //also create_table

110
Q

what additional options are there for table columns

A

limit(size),default,null,precision,scale

you can add these to the migration file as such

:limit => 25

111
Q

does rails auto add a primary key when creating a model

A

true, buy you can supress

112
Q

which migrations are run when you run rake db:migrate

A

all migrations which have not yet been run

113
Q

column migration methods

A

add,remove,rename,change(table,column,type,option)

114
Q

index migrations

A

add_index, remove_incex ; options :unique, :name

115
Q

execute migration method

A

execute(“any sql string”)

116
Q

migration casing

A

Upeper first letter all

117
Q

on new up migrations what happe ns to old ones of same tabless

A

left befind

118
Q

revert migration

A

rake db:migrare VERSION=0

119
Q

if error in migration what happens

A

does everything up until error

120
Q

foreign key

A

ends with _id
t.integer “subject id”
or
t.references :subject

121
Q

active record vs ActiveRecord

A

first is design pattern for relational dbs

second is rails specific for its implmnt

122
Q

active record retrieves data as what instead of a static row

A

object, thus allowing us to manipulate it as such

123
Q

using active record create new insert

A

user=User.new

user. name=”Kevin
user. save

124
Q

activerecord update example

A

user. name=”x”

user. save

125
Q

active record delete

A

user.delete

126
Q

activerecord uses a ruby way of executing what types of statements in an object way

A

sql

127
Q

activerelation

A

aka ARel

oo interpretation of relational algebra or in simple terms

simplifies the generation of db queries, which can be chained, takes care of complex joins and aggregation and not executed until needed

lives behind the scenes of activerecord

128
Q

activerelation example to find, order and include

A

users=User.where(:name=>”x”)
users=user.order(“name ASC”).limit(5)
users=users.include(:articles)

SQL equiv

select users., articles. from users LEFT JOIN articles ON (useers.id=articles.author_id) where useres.name=’x’ order by name asc limit 5

129
Q

rails generating a model

A

rails generate model Subject (singular, camelcase)

  • generates file in db/migrate as timestamp_create_subjects.rb
  • class name :CreateSubjects inherits from ActiveRecord::Migration
  • populate with code to create_table and drop_ :subjects

note how subject is always pluralized after singular creation

-creates file in app/mode;s as subject.rb:
Class name:Subject inherits ActiveRecord::Base

note singular here because it is the model for a single subject

130
Q

does generate do anything that you cant do manually

A

no, just have to do manually and follow rails conventions

131
Q

can you make a model without inheritinc from activerecord

A

yes, just wont be addeed to migrations

132
Q

rails tell a model that the model has a different table name

A
self.table_name = "x"
//useful for legacy code or something that doesnt follow rails conventions
133
Q

rails model file name is lowercased and class is uppercased

A

true

134
Q

activerecord::base adds setter and getter

A

true, dont need to define attr_accessor, unles want something different

135
Q

rails console lets you work with models directly

A

true, accessed with rails c

works like irb, but also lets you work with your application directly, i.e. subject.name=”name”

can access console for different environments like production,test

136
Q

in rails console create does what all in one

A

instantiate obj, set values, and save

137
Q

find subject in console

A

subject=Subject.find(1)//id

138
Q

rails console update

A

subject.update_attributes()

139
Q

rails console destroy

A

keeps object in reference but not in db

delete is alternative to remove ref too

140
Q

rails console find by primary key

A

Subject.find(1)//returns an object or error

141
Q

rails console dynamic finder

A

Subject.find_by_name(“x”), can also use pk, but will return nil instead of error

returns object or nill

142
Q

find first, last and all records in rails console

A
.all,.first.last
//returns object or nil
143
Q

rails console creating a record that already exists i.e. (:position => 3) what happens

A

rails will increment to next avail key

144
Q

rails convention for looking up all records

A
subject= Subject.all
//pluralized first
145
Q

rails conditional query for where

A

Subject.where(:visible => true), returns Activerelation object so it can be chained, also does not execute immediately

146
Q

string sql queries

A

hashes and arrays, safe from sql injecction, sql escaped

147
Q

rails console see current daisy cahined sql that would be executed from activerelation

A

subjects.to_sql

148
Q

lambdas are evaluated when they are called or when they are defined

A

called

149
Q

in rails model, what does scope do and how is it written

A

provides a sort of method kind of.

scope :visible, lambda { where(:visible => true) }

rails console
Subject.visible
//finds visible subjects

150
Q

ActiveRecord defines relationships using whats

A

association

151
Q

three main relational db associations

A

1-1 1-many many-many

152
Q

rails 1:! keyword

A

Classroom has_one :teacher

Teacher belongs_to :classroom

153
Q

rails 1:m keyword

A

Teacher has_many :courses

Course belongs_to :teacher

154
Q

rails m:m keywords

A

Course has_and_belongs_to_many :students
Student “” :courses

(we can create a join table this way using only fks)

155
Q

When to use 1:! association in rails

A

uniqe item a person or thin can have only one of

Student has_one :id_card

or

to break up a single table

Customer has_one :billing_address

156
Q

rails example of 1-1

A

subject-page
Subject has_one :page
Page belongs_to :subjecy

Clss with belongs_to is the one with fk

157
Q

in rails what happens when you use has_one

A

sets up methods:

subject.page which returns relationship

158
Q

remove a relationship from a 1:1

A

subject.page=nil, or .destroy

159
Q

one to many association in rails

A

more common than 1:!, and m:m

Plural names are used for relationship, singular used for belongs_to

returns an array of objects instead of a single object

160
Q

when do you use a 1:m association in rails

A

when an object has many objs which belong to it exclusively

Photogropher has_many :photographs
Photograph belongs_to :Photograph

161
Q

in a table association what keyword tips you off where to put the foreign key

A

belongs_to

162
Q

what methods does has_many add

A

b/c working with arrays:

subject.pages (notice plural)
subject.page &laquo_space;page (appends a page)
.delete(page)
.destroy(page) (remember destroy deletes it from the db
.clear removes all
.empty? checks if its empty, just like on a normal array
.size (just like an array)

in console (when calling it (sql query no longer has limit)

163
Q

m:m association in rails (simple)

A

used when an object has many object belong to it BUT NOT exclusiveley

Project has_and_belongs_to_many collaborators
BlogPost “” :catagories

like have a 1:m relationship– but from both sides at the same time

requires a join table, two foreign keys; index bot keys together

no primary key column

same instance methods get added to the class ass 1:m

164
Q

m:m association in rails (simple) example

A

AdminUser -Page

idea: certain admin users can edit certain pages, so there will be an association between the page and the users who can edit the page (won’t be exclusive)

AdminUser has_and_belongs_to_many :pages
Page “” :admin_uusers

Create Join Table
-use migration

using rails naming convention for join table the this would be:
admin_users_pages

165
Q

Rails join Table naming convention

A

first_table+_+second_table (both plural, and alphabetically ordered)

default- can be configured

BlogPost - Category = blog_posts_categories

166
Q

generate a migration for a join table

A

rails g migration CreateAdminUsersPagesJoin

then you’ll want to add foreign keys to migration and surpress the auto add id

def change
create_table :admin_users_pages, :id => false do |t|
t.integer “admin_user_id”
t.integer”page_id”
end
add index :admin_users_pages, [“fk1”,fk2”]
end

167
Q

in a rails model, for belongs_to, or has_many, how can you specify a different name (or reference) for convenience

A

has_and_belongs_to_many :editors, :class_name =>”AdminUser”

where admin_users is what was replaced

basically tells rails that when we are talking about editors, we’re acually taking about admin_users

168
Q

m:m association in rails (rich)

A

uses a join table, wit two indexed fkeys, but compared to simple, requires a pkey

join table has its own model

not table name convention to follow

work best ending in -ments or -ships (memberships, assignments)

169
Q

create a join table for a m:m(rich)

A

rails generate model SectionEdit

nav to migrations
t.references :admin_user
t.string :summary //contains summary of edits column
t.references :section
end
add_index :Section_edits ["x_id","y_id"]

|t|t

170
Q

perform a rich join in rails console

A

me=AdminUser.find(1)
section=Section.create(:name=>”Section One”, position => 1)

edit=SectionEdit.new

edi. summary=”test edit”
section. section_edits &laquo_space;edit
edit. editor=me
edit. save

171
Q

in rails console does the append operator save the change to the table

A

yes

172
Q

in the rails editor does the equals operator save the change to the table

A

no, use .save

173
Q

in rails console how to reload a change

A

me.section_edits(true)

174
Q

rails console shorthand for creating a new entry in a rich m:m joined table

A
SectionEdit.create(:editor => me, :section => section, :summary => "x")
//assigns both fkeys at same time, but still need to  reload
me.section_edits(true)
175
Q

How to traverse a rich association in rails (how to list all connections with simple way like section.editors) (for a m:m rich relationship)

A

has_and_belongs_to_many :pages
AdminUser has_many :section_edits
AdminUser has_many :sections, :through => :section edits

same for Section

176
Q

in rails what is has_many :through

A

allows “reaching across” a rich join

  • treats rich join lik a HABTM join
  • first step is to create functional rich join for it to work
177
Q

in rails what does the has many :through simulate in SQL

A

Inner Join

178
Q

Standard Rails Crud actions exist?

A

yes

179
Q

What is the standard CRUD creat action in rails

A

new(display new record form), create(process new record form)

180
Q

What is the standard CRUD action in rails for read

A

index (list records)

show(display a single record)

181
Q

What is the standard CRUD action in rails for update

A

edit (display edit record form

update(process delete record form)

182
Q

What is the standard CRUD action in rails for delete

A

delete (display delete record form)

destroy(process delete record form)

183
Q

In CRUD for rails, everything except read essentially has actions for what two thins

A

display, and process

184
Q

Rails terniary action

A

simple way to do an if/else statement, example:

subject.visible ? ‘Yes’ : ‘No’

//if subject is visible output yes, etc

185
Q

in rails CRUD, show requires what

A

an id

186
Q

t/f any template code that can be written with raild/erb can also be written with simple html

A

t

187
Q

create a rails form

A

’%= form_tag(:action => ‘create’) do %’
‘%=text_field(:subject, :name) %’

’%= submit_tag(“Create”) %’
‘%end%’

188
Q

create a rails form_for

A

’%= form_for(:subject, :url => {:action => ‘create’}) do |f|%’
‘%=f.text_field(:name) %’

189
Q

rails CRUD new in the controller does not need code to work to create a new entry (t/f)

A

true, it will load a rails default

but best practice is to add the code like:

@subject= Subject.new

this will allow any defaults you have set to be loaded into the form from the db

you can even set default options from the controller from here like so:

@subject= Subject.new({:name => “Default”})

190
Q

in rails 4, mass assignment filtering protects agains hackers how

A

strong paramaters

strong paramaters cant be turned off with a simple config, they are strong in part by being on by default, each exists in its own controller

191
Q

in rails how do you allow assignment to a strong paramater

A

params.require(:subject)..permit(:name)

require is optional, ensuring that the param is present, and returns the value of the params like a hash

192
Q

createa a rails crud create

A
@subject = Subject.new(subject_params)
if @subject.save
  redirect_to(:action =>'index'
else
  render('new')
end
//end of controller

//private so it cant be called as an action
private
//allows only listed attrs to be mass-assigned, raises an error if subject isn’t present
def subject_params
params.require(:subject).permit(:name, :position)
end

193
Q

what do we need to define for rails crud create

A

a post ability in routes, can change default route to get,post

194
Q

rails crud difference between create vs update

A

update requires id and an existing record
update uses find and update_attributes

create uses new and save
new and create do not need an id

195
Q

rails crud update example

A

@subject=Subject.find(params[:id])
@subject.update_attributes(subject params)//uses the mass assign method
render(‘edit’)

196
Q

rails crud delete and destroy needs an id (t/f)

A

t

197
Q

what doe the yield do in rails in the context of a layout

A

this is where the page yields and uses the layout

a yield statement is used whenever you want to drop the contents or fragments of html content

198
Q

specify the layout in rails to use

A

layout “name”

199
Q

how to specify a dynamic title in rails layout? What about a default if there is no page title?

A

‘title’Simple CMS | ‘%= @page_title || “Default” %’ (end title)

200
Q

where and how to set page title for dynamic use later

A

in the view at the top :

‘%=page_title = “Page” %’

201
Q

what is a partial

A

allow to use reusable html fragments

202
Q

rails convention for naming a partial file

A

starts with _