Skip to content

Instantly share code, notes, and snippets.

1. Name all the 7 (or 8) routes exposed by the resources keyword in the routes.rb file. Also name the 4 named routes, and how the request is routed to the controller/action.
For getting the resources for posts...
```
/, action: index, HTTP verb: GET (name: root)
/posts, action: index, HTTP verb: GET, name: posts
/posts/new, action: new, HTTP verb: GET, name: new_post
/posts, action: create, HTTP verb: POST
/posts/:id, action: show, HTTP verb: GET, name: post
/posts/:id/edit, action: edit, HTTP verb: GET, name: edit_post
@mattdvhope
mattdvhope / gist:8063343
Created December 20, 2013 23:33
Tealeaf Quiz 3
1. What's the difference between rendering and redirecting? What's the impact with regards to instance variables, view templates?
-- Rendering shows the view template. It is able to use the instance variables from the action that has the same name. Redirecting sends a new request to the browser. It uses the route path that is typed in (and the object's id if necessary); the instance variables in the action are not related to the view to which the action redirects.
2. If I need to display a message on the view template, and I'm redirecting, what's the easiest way to accomplish this?
-- Use a flash message in the controller, which will display the message when you click into the template (when you've performed the action that has the flash message in it).
3. If I need to display a message on the view template, and I'm rendering, what's the easiest way to accomplish this?
-- Use a flash message in the controller, which will display the message when you click into the template (when you've performed the acti
2014-06-07T02:32:45.497253+00:00 heroku[router]: at=info method=GET path=/register host=aqueous-badlands-4150.herokuapp.com request_id=5e6a55f9-2307-4ab4-bd7d-4d3867a1baa7 fwd="58.8.175.52" dyno=web.1 connect=2ms service=17ms status=200 bytes=2663
2014-06-07T02:32:45.477733+00:00 app[web.1]: Processing by UsersController#new as HTML
2014-06-07T02:32:45.483591+00:00 app[web.1]: Rendered shared/_header.html.haml (0.2ms)
2014-06-07T02:32:45.484056+00:00 app[web.1]: Completed 200 OK in 6ms (Views: 5.8ms | ActiveRecord: 0.0ms)
2014-06-07T02:32:45.482735+00:00 app[web.1]: Rendered users/new.html.haml within layouts/application (4.0ms)
2014-06-07T02:32:45.475488+00:00 app[web.1]: Started GET "/register" for 58.8.175.52 at 2014-06-07 02:32:45 +0000
2014-06-07T02:32:45.483817+00:00 app[web.1]: Rendered shared/_messages.html.haml (0.1ms)
2014-06-07T02:32:45.920306+00:00 heroku[router]: at=info method=GET path=/favicon.ico host=aqueous-badlands-4150.herokuapp.com request_id=08532e3b-26a6-4d7f-8929-8c7818df336b fwd
2014-11-27T15:51:43.925007+00:00 heroku[router]: at=info method=GET path="/" host=aqueous-badlands-4150-staging.herokuapp.com request_id=21ab95d4-2dbb-4925-9ef9-e133278ea6c4 fwd="171.96.167.70,171.96.167.70" dyno=web.1 connect=1ms service=10ms status=302 bytes=935
2014-11-27T15:51:43.914469+00:00 app[web.1]: Started GET "/" for 171.96.167.70 at 2014-11-27 15:51:43 +0000
2014-11-27T15:51:43.921870+00:00 app[web.1]: Redirected to http://aqueous-badlands-4150-staging.herokuapp.com/home
2014-11-27T15:51:43.917354+00:00 app[web.1]: Processing by PagesController#front as HTML
2014-11-27T15:51:43.922024+00:00 app[web.1]: Completed 302 Found in 5ms (ActiveRecord: 2.1ms)
2014-11-27T15:51:44.548763+00:00 app[web.1]: Redirected to http://aqueous-badlands-4150-staging.herokuapp.com/home
2014-11-27T15:51:44.541492+00:00 app[web.1]: Started GET "/" for 171.96.167.70 at 2014-11-27 15:51:44 +0000
2014-11-27T15:51:44.548867+00:00 app[web.1]: Completed 302 Found in 4ms (ActiveRecord: 1.6ms)
2014-11-27T15:51:44.545173+00:00 app
@mattdvhope
mattdvhope / gist:9aec8eb362e7b4eb51ac
Last active August 29, 2015 14:14
Question about rendering response to ajax request.
# In this controller below, I removed the render :nothing & set up views/choices/update.js.erb
class ChoicesController < ApplicationController
before_action :require_user
def update
respond_to do |format|
format.js {
@choice = Choice.find(params[:id])
choices = @choice.question.choices.where(student_id: current_user.id)
{
"name": "gatsby-starter-default",
"description": "Gatsby default starter",
"version": "1.0.0",
"author": "Matt",
"dependencies": {
"axios": "^0.18.0",
"classnames": "^2.2.6",
"gatsby": "^2.0.19",
"gatsby-image": "^2.0.15",