Skip to content

Instantly share code, notes, and snippets.

@schneems
Created July 19, 2012 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save schneems/3140721 to your computer and use it in GitHub Desktop.
Save schneems/3140721 to your computer and use it in GitHub Desktop.
Week 5 Quiz (Solutions)
## Week 5 Quiz
## 0) Name 3 types of variables in Ruby? Put them in order from least scope to greatest.
a) Local (new = "foo")
b) Instance (@new = "foo")
c) Constant (NEW = "foo")
## 1) Where do SQL queries belong, the view or controller?
Controller
## 2) Controllers are can do 4 types of operations what are they (RRFF)?
Render, Redirect, Filter, Format
## 3) List the actions it usually take to fully implement CRUD in a web app:
show
index
edit
update
new
create
destroy
## 4) What view typically holds a form that submits to the `create` action?
new.html.erb
## 5) What view typically holds a form that submits to the `update` action?
edit.html.erb
## 6) If you forget what routes are available, what command can you run from the command line to help remember?
$ rake routes
## 7) Below is part of a route.rb file that would be mapped to the appropriate controller, replace this with one line of code.
get '/comments'
get '/comments/new'
get '/comments/:id/edit'
get '/comments/:id'
post '/comments'
delete '/comments/:id’
put '/comments/:id'
Answer: resources :comments
## 8) Below is the code for a controller and a view, what controller action will be hit when you click on a link labeled "click me"?
app/controllers/courses_controller.rb
def index
@courses = Course.all
end
app/views/courses/index.html.erb
<h2>Courses</h2>
@courses.each do |course|
<%= link_to "click me", course %>
end
When you click "click me" text, the show action of the courses controller will be executed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment