Books & Videos

Table of Contents

  1. Chapter 1 Getting Started: Really Rapid Rails

    1. Friday, 9 AM

    2. The application needs to do lots of things

    3. So what things do we need for the app?

    4. Rails is for database-centric apps like the ticket sales system

    5. You create a new application with the rails command

    6. Now you need to add your own code to the default app

    7. Scaffolding is GENERATED code

    8. There are no tables in the database yet!

    9. Create the table by running a migration

    10. Sweet! You saved your buddy’s job!

    11. To modify an app, you need to dig into the app’s architecture

    12. The 3 parts of your app: model, view, and controller

    13. The 3 types of code are kept in SEPARATE folders

    14. The files in the VIEW need to be edited

    15. Edit the HTML in the view

    16. Sunday, 8 AM

    17. The application needs to store more information now

    18. A migration is just a Ruby script

    19. Rails can generate migrations

    20. Give your migration a “smart” name, and Rails writes your code for you

    21. You need to run your migration with rake

    22. But changing the database isn’t enough

    23. The concert is a sell-out!

    24. Tools for your Rails Toolbox

  2. Chapter 2 Beyond Scaffolding: Rails apps, made to order

    1. MeBay, Inc. needs your help

    2. Scaffolding does WAY too much

    3. Let’s start by generating the MeBay model...

    4. ...and then we’ll actually create the table using rake

    5. But what about the controller?

    6. The view is created with a page template

    7. The page template contains HTML

    8. A route tells Rails where your web page is

    9. Behind the scenes with routes

    10. The view doesn’t have the data to display app

    11. So what should the page show?

    12. The controller sends the ad to the view

    13. Rails turned the record into an object

    14. The data’s in memory, and the web page can see it

    15. There’s a problem — people can’t find the pages they want

    16. Routes run in priority order

    17. To get data into the view, you will also need code in the controller

    18. An index page will need data from ALL of the records

    19. Ad.find(:all) reads the whole table at once

    20. The data is returned as an object called an array

    21. An array is a numbered sequence of objects

    22. Read all of the ads with a for loop

    23. We need HTML for each element in the array

    24. Rails converts page templates into Ruby code

    25. Loops can be added to page templates using scriptlets

    26. On each pass of the loop, the page generates one link

    27. So what does the generated HTML look like?

    28. You just got an email from the folks at MeBay...

    29. But there are two page templates... should we change the code of each one?

    30. But what about the new static content MeBay sent over?

    31. Tools for your Rails Toolbox

  3. Chapter 3 Inserting, Updating, and Deleting: Everything changes

    1. People want to post new ads online

    2. You already know how to build an app that publishes data from the database

    3. Saving data works just the OPPOSITE of reading data

    4. You need a form to submit data and an action method to save it

    5. Are forms and objects related?

    6. Rails can create forms that are associated with model objects

    7. The @ad form object has not been created

    8. The form object needs to be created before the form is displayed

    9. The forms ad object will be created in the new action of the controller

    10. Each page template now has a matching controller method

    11. The form doesn’t send an object back, it sends DATA back

    12. Rails needs to convert the data into an object before it can be saved

    13. The controller create method, step-by-step

    14. The controller needs to save the record

    15. Don’t create a new page, use an existing one

    16. But how can a controller action display ANOTHER action’s page?

    17. Redirects let the controller specify which view is displayed

    18. But what if an ad needs to be amended after it’s been posted?

    19. Updating an ad is just like creating one... only different

    20. Instead of creating an ad, you need to find one; instead of saving it, you need to update the ad

    21. Restricting access to a function

    22. ...but now old ads need to be deleted

    23. Doing it yourself gave you the power to do more than scaffolding

    24. Tools for your Rails Toolbox

  4. Chapter 4 Database Finders: Truth or consequences?

    1. Keep fit with the Rubyville Health Club

    2. The application actually looks pretty close...

    3. We’re going to fix the scaffolding

    4. Design the search function

    5. Let’s start by building the form

    6. Add the search to the interface

    7. How do we find client records?

    8. We only need those records where client-name = the search string

    9. There’s a finder for every attribute

    10. So what’s next?

    11. We need to match either the client name OR the trainer name

    12. We need to be able to modify the conditions used in the SQL query

    13. Use :conditions to supply SQL

    14. Then there’s a knock at the door...

    15. Tools for your Rails Toolbox

  5. Chapter 5 Validating your Data: Preventing mistakes

    1. Watch out—there’s bad data in the room

    2. Validation code goes in the MODEL

    3. Rails uses validators for simple validation

    4. So how do validators work?

    5. Let’s check if something is a number

    6. Users have been leaving out data on their workout forms

    7. How do we check for mandatory fields?

    8. Validators are simple and work well

    9. Something strange has happened at MeBay

    10. The validators work, but they don’t display errors

    11. If you build your own pages, you need to write your own error message code

    12. The controller needs to know if there was an error

    13. We still need to display error messages!

    14. The MeBay system is looking pretty sweet

    15. Tools for your Rails Toolbox

  6. Chapter 6 Making Connections: Bringing it all together

    1. Coconut Airways need a booking system

    2. We need to see flights and seat bookings together

    3. Let’s look at what the seat scaffolding gives us

    4. We need the booking form and seat list on the flight page

    5. How can we split a page’s content up into separate files?

    6. ERb will ASSEMBLE our pages

    7. So how do we create the booking form partial?

    8. Now we need to include the partial in the template

    9. We need to give the partial a seat!

    10. You can pass local variables to a partial

    11. We also need a partial for the seat list

    12. People are ending up on the wrong flights

    13. A relationship connects models together

    14. But how do we define the relationship?

    15. But some people have too much baggage

    16. We need to write our OWN validation

    17. We need the REVERSE relationship

    18. The system’s taken off at Coconut Airways

    19. Tools for your Rails Toolbox

  7. Chapter 7 Ajax: Avoiding the traffic

    1. There’s a new offer at Coconut Airways

    2. Which parts of a page change most?

    3. Doesn’t the browser always update the entire page?

    4. So what ELSE can make a request?

    5. First we need to include the Ajax libraries...

    6. ...then we need to add an Ajax “Refresh” link

    7. The browser needs to ask for an update

    8. But SHOULD we make the browser ask over and over again?

    9. You listen to a timer like you listen to a button

    10. Someone’s having trouble with their bachelor party

    11. The form needs to make an Ajax request

    12. The form needs to be under the CONTROL of JavaScript

    13. We need to replace the create method

    14. So what effect does this code have?

    15. There’s a problem with the flight bookings

    16. We only know how to update one part of the page at a time

    17. The controller needs to return JavaScript instead of HTML

    18. So what does Rails generate?

    19. If you don’t say where to put the response, it will be executed

    20. Tools for your Rails Toolbox

  8. Chapter 8 XML and Multiple Representations: It all looks different now...

    1. Climbing all over the world

    2. The users hate the interface!

    3. The data needs to be on a map

    4. We need to create a new action

    5. The new action seems to work...

    6. The new page needs a map... that’s the point!

    7. So what code do we need?

    8. The code will only work for localhost

    9. Now we need the map data

    10. What do we need to generate?

    11. We’ll generate XML from the model

    12. A model object can generate XML

    13. What will the controller code look like

    14. Meanwhile, at 20,000 feet...

    15. We need to generate XML and HTML

    16. XML and HTML are just representations

    17. How should we decide which format to use?

    18. How does the map page work?

    19. The code is ready to go live

    20. RSS feeds are just XML

    21. We’ll create an action called news

    22. We have to change the structure of the XML

    23. So we’ll use a new kind of template: an XML builder

    24. Now let’s add the feed to the pages

    25. On top of the world!

    26. Tools for your Rails Toolbox

  9. Chapter 9 REST and Ajax: Taking things further

    1. Too many incidents!

    2. The map could show more details

    3. We can extend the map using Ajax

    4. But how do we convert the index page?

    5. What will the “show” action need to generate?

    6. The new map functionality is a success!

    7. We need to create requests using Ajax, too

    8. The map partial lets us specify a “new” action

    9. How do we PROVE an incident was saved?

    10. The form needs to update the contents of the pop-up’s <div>

    11. Avalanche!

    12. How things works now...

    13. We could have an “Edit” link in the pop-up

    14. We’ll start by modifying the “edit” action

    15. And we’ll also need a new link on the show page

    16. So how do we use the link_to helper?

    17. Ajax links to the rescue

    18. We’re using the wrong route!

    19. The HTTP method affects the route that’s chosen

    20. So what’s an HTTP method?

    21. Head First Climbers needs you!

    22. Tools for your Rails Toolbox

  10. Chapter 10 Real-World Applications: Rails in the real world

    1. Look! It’s a big Ruby “Try this” page

    2. Web apps need testing too

    3. So what kinds of tests are available?

    4. Going live

    5. So how do you change the database?

    6. What’s REST?

    7. The web application that went astray

    8. Living on the Edge

    9. Getting more information

    10. A little light reading...

    11. Head First books on related topics

    12. Tools for your Rails Toolbox

    13. Leaving town...

    14. It’s been great having you here in Railsville!