Skip to content

Instantly share code, notes, and snippets.

@dthtien
Forked from schneems/gist:3079202
Last active May 10, 2017 07:41
Show Gist options
  • Save dthtien/069aa9ad273369b7b7caf79e911004a6 to your computer and use it in GitHub Desktop.
Save dthtien/069aa9ad273369b7b7caf79e911004a6 to your computer and use it in GitHub Desktop.
Week 5 Quiz
## Week 5 Quiz
## 0) Name 3 types of variables in Ruby? Put them in order from least scope to greatest.
1. Local variable(new = "foo")
2. Instan variable(@new="foo")
3.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, ridirect, filter, format
## 3) List the routes it usually take to fully implement CRUD in a web app:
get (show, edit, index)
post (create)
put(update)
path(update)
destroy(delete)
## 4) What view typically holds a form that submits to the `create` action?
new
## 5) What view typically holds a form that submits to the `update` action?
edit
## 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', to: "comments#index"
get '/comments/new', to: "comments#new"
get '/comments/:id/edit', to: "comments#edit"
get '/comments/:id', to: "comments#show"
post '/comments', to: "comments#create"
delete '/comments/:id’, to: "comments#destroy"
put '/comments/:id', to: "comments#edit"
<=> 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
show
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment