Home Page Icon
Home Page
Table of Contents for
I. First Steps with Rails
Close
I. First Steps with Rails
by Timothy Fisher
Ruby on RailsĀ® Bible
Copyright
About the Author
Credits
Acknowledgments
Introduction
Quick Start: Ruby on Rails Quick Start
Installing Instant Rails on Windows
Installing Ruby and Rails on Mac OS X and Linux
Installing on Linux
Installing on Mac OS X
Setting up a Development Environment
Source code version control
IDE or Editor?
TextMate
E
IntelliJ IDEA
NetBeans
Eclipse
Heroku
Aptana Studio
Summary
I. First Steps with Rails
1. Learning Ruby
1.1. The Nature of Ruby
1.1.1. Dynamic or static typing
1.1.2. Duck typing
1.1.3. Compiled or scripting language
1.1.3.1. Compiled languages
1.1.3.2. Scripted languages
1.2. Object Oriented Programming
1.3. The Basics of Ruby
1.3.1. Ruby's interactive shell
1.3.2. Ruby syntax basics
1.3.2.1. Adding comments
1.3.2.2. Using parentheses
1.3.2.3. Using white space
1.3.2.4. Using semicolons
1.3.3. Running Ruby programs
1.4. Classes, Objects, and Variables
1.4.1. Using objects in Ruby
1.4.1.1. Defining objects
1.4.1.2. Writing methods
1.4.1.3. Methods with parameters
1.4.1.4. Creating instances of a class
1.4.1.5. Instance and class methods
1.4.1.6. Instance and class variables
1.4.1.7. Getters and setters in Ruby objects
1.4.2. Inheritance
1.5. Built-in Classes and Modules
1.5.1. Scalar objects
1.5.1.1. Strings
1.5.1.2. Numerics
1.5.1.3. Symbols
1.5.1.4. Times and dates
1.5.2. Collections
1.5.2.1. Arrays
1.5.2.2. Hashes
1.5.2.3. Ranges
1.6. Control Flow
1.6.1. Conditionals
1.6.1.1. The if statement
1.6.1.2. The unless statement
1.6.1.3. The case statement
1.6.2. Loops, blocks, and iterators
1.6.2.1. for loops
1.6.2.2. while and until loops
1.6.2.3. Blocks
1.6.2.4. Iterators
1.6.3. Exception handling
1.6.3.1. Exceptions in Ruby
1.6.3.2. Using begin, raise, and rescue
1.6.3.3. More exception handling using ensure, retry, and else
1.7. Organizing Code with Modules
1.8. Advanced Ruby Techniques
1.8.1. Variable length argument lists
1.8.2. Dynamic programming with method_missing
1.8.3. Reopening classes
1.9. Summary
2. Getting Started with Rails
2.1. What is Ruby on Rails?
2.1.1. DRY
2.1.2. Convention over configuration
2.1.3. Opinionated software
2.2. Rails Architecture
2.2.1. MVC
2.2.2. Rails and MVC
2.3. Rails Scripts
2.3.1. Rails Console
2.3.2. WEBrick
2.3.3. Generators
2.3.4. Migrations
2.4. Your First Rails Application
2.4.1. Create the project
2.4.2. Set up the database
2.4.3. Create the model
2.4.4. Create the controller and views
2.4.4.1. Implementing the index action
2.4.4.2. Implementing the new action
2.4.4.3. Implementing the Create action
2.4.4.4. Implementing the show action
2.4.4.5. Implementing the update action
2.4.4.6. What you have accomplished
2.4.5. Style the application
2.4.6. WebScaffolding
2.4.7. More to Get You Started
2.5. Summary
II. Rails In Depth
3. Using Active Record
3.1. What is Active Record?
3.2. Active Record Basics
3.2.1. Active Record Classes and Objects
3.2.2. Active Record naming conventions
3.2.2.1. Class and table names
3.2.2.2. Table keys
3.3. Setting up a Model
3.3.1. Generate a Rails project and model
3.3.2. Configure Active Record
3.3.3. Rails Development Environments
3.4. Using Migrations
3.4.1. Schema versions
3.4.2. Migration methods
3.4.2.1. Tables
3.4.2.2. Columns
3.4.2.3. Indexes
3.4.3. Inserting data with migrations
3.5. Create, Read, Update, and Delete
3.5.1. Creating records
3.5.2. Reading data
3.5.2.1. Column metadata
3.5.2.2. Accessing attributes
3.5.2.3. Using the find method
3.5.2.4. Dynamic finders
3.5.2.5. Find using SQL
3.5.3. Creating and finding data with the Rails Console
3.5.4. Updating records
3.5.5. Deleting records
3.5.6. Using development log files
3.6. Defining Relationships
3.6.1. One-to-one relationships
3.6.1.1. Methods added by has_one
3.6.1.2. Methods added by belongs_to
3.6.2. Many-to-one relationships
3.6.2.1. Methods added by has_many
3.6.2.2. Methods added by belongs_to
3.6.3. Many-to-many relationships
3.6.3.1. Methods added by has_and_belongs_to_many
3.7. Implementing Validations
3.8. Custom Validations
3.9. Advanced Active Record
3.9.1. Single table inheritance
3.9.2. Composition
3.9.3. Transactions
3.10. Summary
4. Controller: In Depth
4.1. What is ActionController?
4.2. All About Routing
4.2.1. Defining custom routes
4.2.2. Defining a custom default route
4.2.3. Using named routes
4.2.4. Constructing URLs with url_for
4.3. Creating and Using Controllers
4.3.1. Generating controllers
4.3.2. Action methods
4.3.2.1. Using request parameters
4.3.2.2. Rendering templates
4.3.2.3. Redirects
4.3.2.4. Sending feedback with flash
4.3.2.5. Sending other types of data to the browser
4.4. Using Filters
4.4.1. Before filters
4.4.2. After filters
4.4.3. Around filters
4.4.4. Protecting filter methods
4.5. Working with Sessions
4.5.1. Using the ActiveRecord session storage
4.5.2. Using MemCached session storage
4.6. Caching
4.6.1. Page caching
4.6.2. Action caching
4.6.3. Fragment caching
4.7. Summary
5. View: In Depth
5.1. ActionView
5.1.1. Getting to the view
5.1.2. Rendering options
5.1.3. Responding to different formats
5.2. Embedded Ruby
5.2.1. Using the <%- and -%> delimiters
5.2.2. Commenting out embedded Ruby
5.3. Layouts
5.4. Partials
5.5. Helpers
5.5.1. Predefined Rails Helpers
5.5.1.1. HTML Creation Helpers
5.5.1.2. Form Creation Helpers
5.5.1.3. JavaScript Creation Helpers
5.5.1.4. Data Processing Helpers
5.5.1.5. Debugging Helpers
5.5.2. Creating Your Own Block Helpers
5.6. JavaScript, Ajax, and RJS
5.6.1. Prototype Helpers
5.6.2. RJS helpers
5.7. Summary
III. Developing a Complete Rails Application
6. Developing Book Shelf: The Basic Framework
6.1. Application Overview
6.2. Creating a Skeleton for the Application
6.2.1. Begin the Book Shelf project
6.2.2. Setting up the databases
6.2.2.1. Create the databases
6.3. Create a Home Page
6.3.1. Create the Home controller
6.3.2. Create a layout and view
6.3.2.1. The HTML head
6.3.2.2. The body header section
6.3.2.3. The body sidebar section
6.3.2.4. The body content section
6.3.2.5. Creating the index view template
6.3.2.6. Testing the home page
6.3.2.7. Add some style
6.3.3. Set up a default route
6.4. Implementing Users
6.4.1. Create the user model
6.4.1.1. Securing user passwords
6.4.1.2. Generate the user model
6.4.1.3. Create the user migration
6.4.1.4. Add user model validations
6.4.2. Implement user registration
6.4.2.1. Create a user controller
6.4.2.2. Handle the user password
6.4.2.3. Create a registration view
6.4.2.4. Create user home view
6.4.3. Implement login and logout
6.4.3.1. Create login action method
6.4.3.2. Create the logout action method
6.4.3.3. Create an application login partial
6.4.3.4. Test the login and logout functionality
6.4.4. Using a before filter to protect pages
6.4.4.1. Modify the application controller
6.4.4.2. Add login form to the signup page
6.5. Summary
7. Developing Book Shelf: Adding the Core Functionality
7.1. Adding Support for Books
7.2. Refactor the sidebar code
7.3. Integrating with Amazon
7.3.1. Install Ruby/Amazon
7.3.2. Implement the Book Shelf-Amazon interface
7.3.2.1. The initialize method
7.3.2.2. The find_by_keyword method
7.4. Implementing a Search
7.4.1. Create the book search form
7.4.2. Generate the book controller and search action
7.4.3. Create the book model
7.4.3.1. Generate the book model class
7.4.3.2. Create the book migration
7.4.3.3. Run the migration
7.4.3.4. Associate the book model and the user model
7.4.4. Implement search logic in the book model
7.4.5. Create the search results page
7.4.6. Implement search results paging
7.5. Implementing the Addition and Deletion of Books
7.5.1. Adding a book
7.5.2. Deleting a book
7.5.2.1. Add the delete action
7.5.2.2. Update the page with RJS
7.6. Displaying a User's Books
7.7. Implementing the Book Detail Page
7.8. Summary
8. Developing Book Shelf: Social Support
8.1. Adding Social Support
8.2. Implementing Tagging
8.2.1. Installing a tagging plugin
8.2.1.1. Install the acts_as_taggable_redux plugin
8.2.2. Setting up the database for tagging support
8.2.3. Adding tagging support to the models
8.2.4. Adding tagging support to the controllers
8.2.5. Creating the view layer for tagging
8.2.5.1. Implementing the sidebar tag cloud view
8.2.5.2. Implement tag_cloud_revised helper method
8.2.5.3. Generate the tagging style sheet
8.2.5.4. Implement the static tag view
8.2.5.5. Make the tags editable
8.2.5.6. Implement the show_for_tag view
8.2.6. Using tags
8.3. Implementing Book Reviews
8.3.1. Implementing the review model
8.3.2. Adding associations to the book and user models
8.3.3. Implementing the review view
8.3.3.1. Displaying reviews for a book
8.3.3.2. Implementing the review entry form
8.3.4. Implementing the review controller
8.3.5. Adding some style
8.3.6. Adding a book review
8.4. Implementing Book Ratings
8.5. Extending the Application
8.5.1. Improving the user interface
8.5.2. Implementing an administrator interface
8.5.3. Adding RSS feeds to the application
8.5.4. Adding support for other book information sources
8.5.5. Implementing recommendations and suggestions
8.5.6. Expanding user profiles and adding avatars
8.6. Summary
9. Testing the Book Shelf Application
9.1. Why Test?
9.2. Using Test::Unit
9.2.1. Test assertions
9.2.2. Test fixtures
9.2.3. Test methods
9.2.4. Test runners
9.2.5. Test suites
9.3. Testing in Rails
9.3.1. Rails test directory
9.3.2. Rails test lifecycle
9.4. Setting Up a Test Database
9.5. Functional Tests
9.5.1. Running a test
9.5.2. Creating a test
9.5.2.1. Setting up fixtures
9.5.2.2. Writing a test method
9.5.2.3. More assertion methods
9.5.2.4. Verifying your test
9.5.3. Adding more tests
9.5.3.1. Add some reviews
9.5.3.2. Verify the tests again
9.6. Unit Tests
9.6.1. Setting up user fixtures
9.6.2. Test authentication
9.6.3. Test validations
9.6.3.1. Test valid password
9.6.3.2. Test valid login
9.6.3.3. Test valid e-mail
9.7. Integration Tests
9.8. Running All Tests
9.9. Test Coverage
9.10. Debugging Techniques
9.10.1. The Rails log files
9.10.2. Console-based
9.10.3. Using the debugger
9.11. Summary
IV. Advanced Rails
10. Using Prototype and script.aculo.us
10.1. Prototype, script.aculo.us, and Rails
10.1.1. Using Prototype and script.aculo.us from Rails
10.1.2. Create a Rails project
10.1.2.1. Include the Prototype and script.aculo.us files
10.2. Prototype Overview
10.2.1. Ruby's influence on Prototype
10.2.2. What is Prototype?
10.3. Extensions to JavaScript
10.3.1. Simplifying JavaScript with the dollar sign
10.3.1.1. Selecting elements with $
10.3.1.2. Selecting elements with $$
10.3.1.3. Creating arrays with $A
10.3.1.4. Splitting strings with $w
10.3.1.5. Getting form field values with $F
10.3.1.6. Creating hashes with $H
10.3.1.7. Creating ranges with $R
10.3.2. More powerful arrays
10.3.2.1. Enumerating an array
10.3.3. JSON support
10.4. OOP with Prototype
10.4.1. Defining classes and inheritance
10.4.2. Implementing class inheritance with Prototype
10.5. Event Handling
10.6. Ajax
10.6.1. Ajax links
10.6.2. Ajax link options
10.7. script.aculo.us Overview
10.8. Visual Effects
10.8.1. script.aculo.us effects
10.8.2. Effect options
10.8.3. Using combination effects
10.9. Controls
10.9.1. Sliders
10.9.2. Auto-completion
10.9.3. In-place editing
10.9.3.1. Implementing a single value in-place editor
10.10. Drag and Drop
10.10.1. Creating draggable elements
10.10.1.1. Draggable options
10.10.2. Creating droppable elements
10.10.2.1. Droppable options
10.10.3. Sortable lists
10.11. JavaScript Testing
10.11.1. Creating JavaScript unit tests
10.11.2. Running JavaScript unit tests
10.12. Summary
11. Extending Rails
11.1. Beyond the Core
11.2. Generators
11.2.1. The generator directory structure
11.2.2. Writing generator code
11.2.3. Creating the templates
11.2.4. Running the new authentication generator
11.2.5. Extending Rails::Generator::NamedBase
11.3. Plugins
11.3.1. Using the Plugin script
11.3.1.1. List available plugins
11.3.1.2. List plugin sources
11.3.1.3. Adding and removing plugin sources
11.3.1.4. Discover new plugin sources
11.3.1.5. Installing, removing, and updating plugins
11.3.2. Writing a plugin
11.3.2.1. Write a new plugin
11.3.2.2. Try out the new plugin
11.3.3. Common techniques used to develop plugins
11.3.3.1. Extending classes with mixins
11.3.3.2. Opening a class
11.3.3.3. Dynamic extension with callbacks and hooks
11.3.3.4. Using code generation
11.3.4. Managing plugins with Piston
11.4. Summary of Useful Plugins
11.4.1. acts_as_rateable
11.4.2. Pagination
11.4.2.1. Installing will_paginate
11.4.2.2. Adding pagination to your application
11.4.3. acts_as_state_machine
11.4.3.1. Installing acts_as_state_machine
11.4.3.2. Using acts_as_state_machine
11.4.4. annotate_models
11.4.4.1. Installing annotate_models
11.4.4.2. Using annotate_models
11.4.5. exception_notifier
11.4.5.1. Installing exception_notifier
11.4.5.2. Using exception_notifier
11.4.6. resource_controller
11.4.6.1. Installing resource_controller
11.4.6.2. Using resource_controller
11.4.7. Adding user authentication
11.4.7.1. Installing restful_authentication
11.4.7.2. Using restful_authentication
11.4.8. Enhanced scaffolding
11.4.8.1. Streamlined
11.4.8.2. ActiveScaffold
11.4.9. Implementing content tagging
11.4.10. Handling file uploads
11.4.10.1. attachment_fu
11.5. Engines
11.5.1. Install the Engines plugin
11.5.2. Generate the engine skeleton
11.5.3. Move your application files into the engine
11.5.4. Modify your environment
11.5.5. Include your engine in your application
11.6. Summary
12. Advanced Topics
12.1. Beyond the Basics
12.2. RESTful Rails
12.2.1. Some advantages of RESTful architecture
12.2.2. REST as a Web service architecture
12.2.3. REST and representations
12.2.4. Writing a RESTful application with Rails
12.2.4.1. Rails routing and REST
12.2.4.2. PUT and DELETE full disclosure
12.2.4.3. Generate a RESTful resource
12.3. Working with Legacy Databases
12.3.1. Override database table and field names
12.3.2. Side by side with the legacy database
12.4. Using ActionMailer
12.4.1. Configuring a Rails application for e-mail support
12.4.2. Generating a mailer model
12.4.3. Writing code to send e-mail
12.4.4. Writing code to receive e-mail
12.5. ActiveResource and XML
12.6. Deploying with Capistrano
12.6.1. Installing and setting up Capistrano
12.6.2. Running basic Capistrano tasks
12.6.3. Customizing Capistrano
12.7. Summary
V. Appendixes
A. Ruby Quick Reference
A.1. Basic Ruby Syntax
A.1.1. Literal expressions
A.1.1.1. Arrays
A.1.1.2. Boolean literals
A.1.1.3. Hashes
A.1.1.4. Numbers
A.1.1.5. Ranges
A.1.1.6. Regular expressions
A.1.1.7. Strings
A.1.1.8. Symbols
A.1.2. Variable and method names
A.1.3. Operators
A.1.4. Method calls
A.1.5. Special keyword expressions
A.1.5.1. The if expression
A.1.5.2. The unless expression
A.1.5.3. The case expression
A.1.5.4. The for expression
A.1.5.5. The while expression
A.1.5.6. The until expression
A.1.5.7. Loop control keywords
A.1.6. Assignment
A.1.7. File input and output
A.1.8. Exceptions
A.2. Objects and Classes
A.2.1. Defining methods
A.2.2. Blocks
A.2.3. Defining classes and modules
A.2.3.1. Defining modules
A.2.3.2. Defining classes
A.2.3.3. Superclasses and self
A.2.3.4. Including and extending with modules
A.2.3.5. Attributes
A.2.3.6. Access control
A.2.4. Method lookup
B. Ruby on Rails Guide
B.1. Getting Started
B.1.1. Standard Rails application
B.1.2. Generators
B.2. Controllers and Helpers
B.2.1. Traditional routing
B.2.2. RESTful routing
B.2.3. Controller variables
B.2.4. Filters
B.2.5. Rendering and redirecting
B.2.6. Respond to
B.2.7. Helpers
B.3. Views
B.3.1. ERb
B.3.2. RJS
B.4. Models
B.4.1. Creating
B.4.2. Reading
B.4.3. Updating
B.4.4. Deleting
B.4.5. Relationships
B.4.5.1. belongs_to
B.4.5.2. has_one
B.4.5.3. has_many
B.4.5.4. has_and_belongs_to_many
B.5. Database Migrations
B.6. Plugins
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Quick Start: Ruby on Rails Quick Start
Next
Next Chapter
1. Learning Ruby
Part I. First Steps with Rails
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset