Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Rails: Novice to Ninja
Notice of Rights
Notice of Liability
Trademark Notice
About Glenn Goodrich
About SitePoint
Preface
Who Should Read This Book
Conventions Used
Code Samples
Tips, Notes, and Warnings
Supplementary Materials
Chapter 1: Introducing Ruby on Rails
History
Development Principles
Optimize for Programmer Happiness
Convention Over Configuration
The Menu is Omakase
No One Paradigm
Exalt Beautiful Code
Value-integrated Systems
Progress Over Stability
Push Up a Big Tent
Building the Example Web Application
Features of the Example Application
Summary
Chapter 2: Getting Started
What does all this cost?
Installing on Windows
Install Ruby
Installing on Mac OS X
Installing Homebrew
Installing on Linux (Ubuntu)
Additional Installation Options
And Now the Fun Begins
One Directory Structure to Rule Them All
Creating the Standard Directory Structure
Starting Our Application
Version Control and Git
Git Basics
Which Text Editor?
Windows and Cross-platform Text Editors
Linux and Mac OS X Editors
IDEs
Summary
Chapter 3: Introducing Ruby
Ruby is a Scripting Language
Compiled Languages
Scripting Languages
The Great Performance Debate
Choose What Works
Ruby is an Object Oriented Language
Reading and Writing Ruby Code
The Interactive Ruby Shell (irb)
Interacting with Ruby Objects
Literal Objects
Variables and Constants
Basic Punctuation in Ruby
Dot Notation
Chaining Statements Together
Use of Parentheses
Method Notation
Object-oriented Programming in Ruby
Classes and Objects
Object-level Functionality
Instance Variables
Instance Methods
Accessor Methods
Class-level Functionality
Inheritance
Modules and Composition
Return Values
Standard Output
Ruby Core Classes
Strings
Numerics
Symbols
Arrays
Hashes
nil Values
Running Ruby Files
Control Structures
Conditionals
Loops
Blocks, Procs, and Lambdas. Oh my!
Summary
Chapter 4: Rails Revealed
Three Environments
Application Dependencies
Bundler
Database Configuration
The Database Configuration File
The Model-View-Controller Architecture
MVC in Theory
MVC the Rails Way
The ActiveRecord Module
The ActionPack Library
ActionController (the Controller)
ActionView (the View)
RESTful-style
In Theory
REST and the Web
REST in Rails
Code Generation
The ActionMailer Component
Testing and Debugging
Testing
Debugging
Summary
Chapter 5: Models, Views, and Controllers
Generating a Model
The Model Generator
Modifying the Schema Using Migrations
Creating a Skeleton Migration File
Creating the stories Table
Running the Migration
Managing Data Using the Rails Console
Creating Records
Retrieving Records
Updating Records
Deleting Records
Generating a Controller
Running the generate Command
Understanding the Output
Starting Our Application … Again
Creating a View
Generating Views with Scaffolding
Creating Static Pages
Creating Dynamic Pages
Passing Data Back and Forth
Pulling in a Model
Summary
Chapter 6: Helpers, Forms, and Layouts
Calling upon Our Trusty Helpers
Enabling Story Submission
Creating a Form
Saving Data to the Database
Redirecting with URL helpers
Creating a Layout
Establishing Structure
Adding Some Style
Enabling User Feedback with the Flash
Adding to the Flash
Retrieving Data from the Flash
Applying Validations
Tweaking the Redirection Logic
Improving the User Experience
Testing the Form
Testing the Model
Analyzing the Skeleton File
Using Assertions
Writing a Unit Test
Running Model Tests
Testing the Controller
Analyzing the Skeleton File
Writing a Controller Test
Running a Controller Test
Writing More Controller Tests
Running the Complete Test Suite
Visiting the Logs
Summary
Chapter 7: Ajax and Turbolinks
Generating a Vote Model
Creating the Model
Examining the Vote Migration
Applying the Migration
Introducing Relationships
Introducing the has_many Clause
Introducing the belongs_to Clause
How's our schema looking?
Making a Home for Each Story
Determining Where a Story Lives
Displaying Our Stories
Improving the Story Randomizer
Implementing Clean URLs
Converting from Strings
Investigating Link Generation
Ajax, Pjax, and Turbolinks
Introducing Ajax
Making Stories
Controlling Where the Votes Go
The Asset Pipeline
Why do we need an asset pipeline?
Multiple Source Files
Asset Preprocessors
Asset Compression and Minification
Asset Digests
Get Out the Vote
Styling the Scoreboard
Response Formats
Introducing Partials
Adding Voting History
Creating the Partial
Styling the Voting History
Tweaking the Voting History
Testing the Voting Functionality
Testing the Model
Preparing the Fixtures
Testing a Story's Relationship to a Vote
Testing the Voting History Order
Running the Unit Tests
Testing the Controller
Testing Page Rendering
Testing Vote Storage
Testing Ajax Voting
Testing Regular HTTP Voting
Running the Full Test Suite
Summary
Chapter 8: Protective Measures
Introducing Sessions and Cookies
Identifying Individual Users
What's a cookie?
What's a session?
Sessions in Rails
Modeling the User
Generating a User Model
Has Secure Password
Adding Relationships for the User Class
Creating a User
Developing Login Functionality
Creating the Controller
Creating the View
Adding Functionality to the Controller
Introducing Filters
Before Filters
After Filter
Around Filters
Managing User Logins
Retrieving the Current User
Displaying the Name of the Current User
Allowing Users to Log Out
Adding a Navigation Menu
Restricting the Application
Protecting the Form
Restricting Access to Story Submission
Associating Stories with Users
One Last Thing: Associate Votes to Users
Testing User Authentication
Testing the Model
Testing the Controllers
Fixing VotesController Tests
Running the Full Test Suite
Summary
Chapter 9: Advanced Topics
Promoting Popular Stories
Using a Counter Cache
Introducing the Counter Cache
Making Room for the Cache
Applying the Migration
Implementing the Front Page
Modifying the Controller
Modifying the View
Creating the Partial
Styling the Front Page
Setting the Default Page
Implementing the Voting Bin
Adding Custom Actions to RESTful Routes
Abstracting Presentation Logic
Avoiding Presentation Logic Spaghetti
Introducing ActionView Helpers
Writing an ActionView Helper
Expanding the Navigation Menu
Requiring a Login to Vote
Auto-voting
Introducing Model Callback
Adding a Callback
Adding a Description to Stories
Adding a Model Attribute
Expanding the Submission Form
Whitelisting the New Attribute
Adding User Pages
Introducing the Join Model Relationship
Introducing the has_many :through Association
Adding Another Controller
Creating the View
Testing the New Functionality
Testing the Model
Testing the StoriesController
Testing the VotesController
Testing the UsersController
Running the Complete Test Suite
Summary
Chapter 10: Rails Plugins
What is a plugin?
Adding Tagging to Readit
Introducing the acts-as-taggable-on Gem
Installing the acts-as-taggable-on Gem
Creating a Migration for the Plugin
Understanding Polymorphic Associations
Making a Model Taggable
Enabling Tag Submission
Modifying the View
Modifying the Controller
Enabling Tag Display
Modifying the View
Updating the story Partial
Assigning Our First Tags
Viewing Stories
Creating the Controller
Filling in the View Template
Displaying Tagged Stories
Creating a tag Partial
Updating the Stylesheet
Testing the Tagging Functionality
Testing the Model
Testing the Controller
Running the Test Suite ... Again!
Summary
Chapter 11: Debugging, Testing, and Benchmarking
Debugging Your Application
Debugging within Templates
Web Console
Debugging A Slightly Trickier Bug
Using the Rails Logging Tool
Overcoming Problems in Debugging
Testing Your Application Using Integration Tests
Using Breakpoints in a Test
Revisiting the Rails Console
A Brief Introduction to Pry
Benchmarking Your Application
Taking Benchmarks from Log Files
Manual Benchmarking
Summary
Chapter 12: Deployment and Production Use
The Implications of “Production”
Choosing a Production Environment
Web Servers
Apache
Nginx
Application Servers
Rack
Terminology
Application Servers for Rails
Proxying Requests
Software as a Service
Heroku
Alternatives for Session Storage
The ActiveRecord Store Session Container
Further Reading
Caching
ActionCable
Rails API
Performance
Summary
← Prev
Back
Next →
← Prev
Back
Next →