Skip to content

Instantly share code, notes, and snippets.

@knwang
Created December 1, 2014 20:00
Show Gist options
  • Save knwang/8c441eceaa3782d7b3c3 to your computer and use it in GitHub Desktop.
Save knwang/8c441eceaa3782d7b3c3 to your computer and use it in GitHub Desktop.
Simplest Rails
1. Route, ApplicationsController that renders some HTML
2. Separate content and flow control - HTML as "views"
3. dynamically generated pages
- data with different time
- render template, passing in the data
- render "dir/hello_world.html", locals: {time: "am"}
- data from the URL
- /hello/:name?foo=bar
- data from the db (next chapter)
No Magic Rails
4. database backend apps
- SQL code to create tables (posts) and some posts - execute SQL
- show posts on the page
- show a post on the page
5. collecting user's input
- forms (create)
- dealing with post params
- execute SQL to create/update posts
- destroy a post (id)
6. extract model class
- self.new
- self.create
- self.find(id)
- update
- destroy
7. validations
8. migration to add comments
9. associations
- show all comments for a post (with SQL, in the controller)
- move this logic to Post class (def comments)
- add a comment (def comments<<(comment))
- delete all comments (def comment_ids and def destroy_all_comments)
Magic Rails
Routing
Layout and Views
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment