Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Buy Now $39.99
Standard view
Full view
of .
Save to My Library
Look up keyword or section
Like this
15Activity

Table Of Contents

The application needs to do lots of things
So what things do we need for the app?
You create a new application with the rails command
Now you need to add your own code to the default app
Scaffolding is GENERATED code
There are no tables in the database yet!
Create the table by running a migration
Sweet! You saved your buddy's job!
To modify an app, you need to dig into the app's architecture
The 3 parts of your app: model, view, and controller
rails exposed
Rails Exposed
The 3 types of code are kept in SEPARATE folders
The files in the VIEW need to be edited
Edit the HTML in the view
The application needs to store more information now
A migration is just a Ruby script
Rails can generate migrations
You need to run your migration with rake
But changing the database isn't enough
Scaffolding does WAY too much
Let’s start by generating the MeBay model
... and then we’ll actually create the table using rake
But what about the controller?
The view is created with a page template
The page template contains HTML
A route tells Rails where your web page is
The view doesn’t have the data to display app
So what should the page show?
An array is a numbered sequence of objects
Read all of the ads with a for loop
We need HTML for each element in the array
Rails converts page templates into Ruby code
Loops can be added to page templates using scriptlets
On each pass of the loop, the page generates one link
So what does the generated HTML look like?
But what about the new static content MeBay sent over?
People want to post new ads online
Saving data works just the OPPOSITE of reading data
You need a form to submit data and an action method to save it
Are forms and objects related?
Rails can create forms that are associated with model objects
The @ad form object has not been created
The form object needs to be created before the form is displayed
Each page template now has a matching controller method
The form doesn’t send an object back, it sends DATA back
Rails needs to convert the data into an object before it can be saved
The controller needs to save the record
Don’t create a new page, use an existing one
But how can a controller action display ANOTHER action’s page?
Redirects let the controller specify which view is displayed
But what if an ad needs to be amended after it’s been posted?
Updating an ad is just like creating one... only different
Restricting access to a function
... but now old ads need to be deleted
Doing it yourself gave you the power to do more than scaffolding
Keep fit with the Rubyville Health Club
The application actually looks pretty close
We’re going to fix the scaffolding
Design the search function
Let’s start by building the form
Add the search to the interface
How do we find client records?
There’s a finder for every attribute
We need to match either the client name OR the trainer name
Finders write database queries
We need to be able to modify the conditions used in the SQL query
Use :conditions to supply SQL
Watch out—there’s bad data in the room
Validation code goes in the MODEL
Rails uses validators for simple validation
So how do validators work?
Let’s check if something is a number
Users have been leaving out data on their workout forms
How do we check for mandatory fields?
Validators are simple and work well
Something strange has happened at MeBay
Coconut Airways need a booking system
We need to see flights and seat bookings together
Let’s look at what the seat scaffolding gives us
You can pass local variables to a partial
We also need a partial for the seat list
People are ending up on the wrong flights
A relationship connects models together
But how do we define the relationship?
But some people have too much baggage
We need to write our OWN validation
We need the REVERSE relationship
The system’s taken off at Coconut Airways
There’s a new offer at Coconut Airways
Which parts of a page change most?
Doesn’t the browser always update the entire page?
So what ELSE can make a request?
First we need to include the Ajax libraries
...then we need to add an Ajax “Refresh” link
The browser needs to ask for an update
But SHOULD we make the browser ask over and over again?
You listen to a timer like you listen to a button
ajax exposed
Ajax Exposed
Someone’s having trouble with their bachelor party
The form needs to make an Ajax request
The form needs to be under the CONTROL of JavaScript
We need to replace the create method
So what effect does this code have?
There’s a problem with the flight bookings
We only know how to update one part of the page at a time
The controller needs to return JavaScript instead of HTML
Now we need the map data
What do we need to generate?
We’ll generate XML from the model
A model object can generate XML
What will the controller code look like
Meanwhile, at 20,000 feet
We need to generate XML and HTML
XML and HTML are just representations
How should we decide which format to use?
How does the map page work?
The code is ready to go live
RSS feeds are just XML
We’ll create an action called news
We have to change the structure of the XML
So we’ll use a new kind of template: an XML builder
Now let’s add the feed to the pages
On top of the world!
Too many incidents!
The map could show more details
We can extend the map using Ajax
But how do we convert the index page?
What will the “show” action need to generate?
The new map functionality is a success!
We need to create requests using Ajax, too
The map partial lets us specify a “new” action
How do we PROVE an incident was saved?
The form needs to update the contents of the pop‑up’s <div>
Avalanche!
How things works now
We could have an “Edit” link in the pop‑up
We’ll start by modifying the “edit” action
And we’ll also need a new link on the show page
So how do we use the link_to helper?
Ajax links to the rescue
We’re using the wrong route!
The HTTP method affects the route that’s chosen
So what’s an HTTP method?
Head First Climbers needs you!
Look! It’s a big Ruby “Try this” page
Web apps need testing too
So what kinds of tests are available?
So how do you change the database?
The web application that went astray
Living on the Edge
Getting more information
A little light reading
Head First books on related topics
0 of .
Results for:
No results containing your search query
P. 1
Head First Rails: A learner's companion to Ruby on Rails

Head First Rails: A learner's companion to Ruby on Rails

Ratings:

3.25

(2)
|Views: 2,305 |Likes:

Ready to transport your web applications into the Web 2.0 era? Head First Rails takes your programming -- and productivity -- to the max. You'll learn everything from the fundamentals of Rails scaffolding to building customized interactive web apps using Rails' rich set of tools and the MVC framework. Please note this book covers Rails 2.

By the time you're finished, you'll have learned more than just another web framework. You'll master database interactions, integration with Ajax and XML, rich content, and even dynamic graphing of your data -- all in a fraction of the time it takes to build the same apps with Java, PHP, ASP.NET, or Perl. You'll even get comfortable and familiar with Ruby, the language that underpins Rails. But you'll do it in the context of web programming, and not through boring exercises such as "Hello, World!"

Your time is way too valuable to waste struggling with new concepts. Using the latest research in cognitive science and learning theory to craft a multi-sensory learning experience, Head First Rails uses a visually rich format designed to take advantage of the way your brain really works.

Ready to transport your web applications into the Web 2.0 era? Head First Rails takes your programming -- and productivity -- to the max. You'll learn everything from the fundamentals of Rails scaffolding to building customized interactive web apps using Rails' rich set of tools and the MVC framework. Please note this book covers Rails 2.

By the time you're finished, you'll have learned more than just another web framework. You'll master database interactions, integration with Ajax and XML, rich content, and even dynamic graphing of your data -- all in a fraction of the time it takes to build the same apps with Java, PHP, ASP.NET, or Perl. You'll even get comfortable and familiar with Ruby, the language that underpins Rails. But you'll do it in the context of web programming, and not through boring exercises such as "Hello, World!"

Your time is way too valuable to waste struggling with new concepts. Using the latest research in cognitive science and learning theory to craft a multi-sensory learning experience, Head First Rails uses a visually rich format designed to take advantage of the way your brain really works.

More info:

Publish date: Dec 30, 2008
Added to Scribd: May 16, 2009
Copyright:Traditional Copyright: All rights reservedISBN:9780596800833
List Price: $39.99 Buy Now

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
Buy the full version from:Amazon
See more
See less

07/29/2014

464

9780596800833

$39.99

USD

pdf

original

You're Reading a Free Preview
Pages 19 to 99 are not shown in this preview.
You're Reading a Free Preview
Pages 118 to 237 are not shown in this preview.
You're Reading a Free Preview
Pages 256 to 257 are not shown in this preview.
You're Reading a Free Preview
Pages 276 to 332 are not shown in this preview.
You're Reading a Free Preview
Pages 351 to 464 are not shown in this preview.

Activity (15)

You've already reviewed this. Edit your review.
snifty_1 reviewed this
I have a *ton* of Rails books, and I have to say that this one has probably done the most to help me really start to wrap my head around how Rails works. I've been a big fan of the Head Start series ever since I picked up their book on XHTML & CSS. Even though I pretty much knew all the material in that book, I liked reading it because the explanatory approach is just fun to go through. With this Rails book, it's still fun, but more importantly, it's *memorable*. There must be something to all that mumbo-jumbo about neuroscience and whatnot behind the Head First series. Ideas and techniques are introduced, and then re-introduced in a different way. Also, unlike the 'standard' Rails book, "Agile Web Development with Rails," this book has a whole bunch of different applications, a new one every chapter or two. By the end of AWDWR, I was sick of the "Depot" application. This book kept my interest up.
1 hundred reads
1 thousand reads
shahsubhash liked this
mozeml liked this
Ronnie Ho liked this
jurish_ali4253 liked this
Chinmay Bhat liked this
Chinmay Bhat liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->