Most Download Books

Practical Rails Social Networking Sites – Apress

Free Download Networking Books |
Click Here To Download Book
Pages 446
Views 14677
Size 7.2 MB
Download 118

Table Of Contents 8

CHAPTER 1 Ruby, Ruby on Rails, and the RailsCoders Project 26

The RailsCoders Project 26

Ruby and Ruby on Rails 27

A Brief History of Ruby 28

What Is Ruby on Rails? 29

Software Required to Build RailsCode32

Upgrading Rail33

Installing Ruby, Rails, and MySQ33

Installing on Windows 34

Mac OS X 36

Linux 37

Creating the Skeleton of the Rails Application 39

Watching the Rails Logfile41

Setting up the Database42

Creating the Database43

Configuring Rails to Use the Database43

Testing the Database44


■CHAPTER 2 Developing a Content Management System.46

Specifying the Feature Requiremen46

Rails, Routing, and REST 46

Traditional Rails Routes 47

RESTful Rails Routes 47

Creating a Site Layout 48

Designing the Pages and Page Editor51

The Page Model51

The Page Controller 52

Creating the Page Model 53


Creating the Mode54

Creating the Controller58

Setting Up a Default Page 66

Adding a Link from the Sidebar Menu66


Creating the Testing Database67

Developing Unit Tests for the Page Model 67

Extending the Content Management System69


■CHAPTER 3 Adding Users and Group72

Specifying the Feature Requiremen72

Defining the User Model 72

The Role Model and Join Table73

The Controllers .74

Sessions and Cookies75

Creating the User Model 76

The Session-Handling Library 78

Creating the Controllers80

The Users Controller 80

The Account Controller82

Creating the User Account View83

The New User View 83

The Login View .86

The Show User View 87

Adding Administration View88

Listing All Users in the Index Vie89

Editing a User with edit.rhtml 91


Unit Testing 92

Functional Testin93

Adding Roles.97

Creating the Role Model and Join Tabl97

Checking a User’s Role99

Administering Roles 101

Testing the Roles Functionality104

Extending the User Management System .106


■CHAPTER 4 Building a News Blog with RSS Feeds and an API .108

Specifying the Feature Requiremen108

Textile Markup .108

The Article Model 109

Defining the Category Model110

The Editor Role .110

The Articles Controller111

The Categories Controller 111

Installing the RedCloth Ge111

Creating the Article and Category Models .112

Writing the Database Migration112

Defining the Relationships Among Models 113

Defining the Validations 114

Automatically Nullifying category_id on Deletio114

Automatically Updating the published_at Fiel114

Adding the Editor Role115

Creating the Articles Controller and Views .116

Mapping the REST Resources 116

The Articles Controller117

The Article Views 123

Using the Articles Feature .126

Testing the XML API 126

Adding HTTP Authentication for the API128

Testing the API Authentication129

Creating the Categories’ Controller and Views130

The Categories Controller130

The Category Views 133

Adding a Link from the Sidebar Menu 134

Manually Testing the News Blog System .135

Testing the News Blog135

Functional Tests 137

Integration Tests 139

Further Development of the News System 140

Summary 141

■CHAPTER 5 Building a Discussion For142

Specifying the Discussion Forum Requirements 142

Defining the Forum Mode143

Defining the Topic Model 143

Defining the Post Mode144

The Moderator Role 144

The Forum, Topic, and Post Controller144

Building the Forum .145

Building the Forum, Topic, and Post Models 145

Checking a User’s Roles for Moderator Rights 151

Adding the Nested Resource Route Mappings 151

Modifying the Layout Template and Style Shee151

The Forums Controller and View152

The Topics Controller and Views 156

The Posts Controller and View161

Adding a Link to the Sidebar Menu .166

Testing the Topics and Posts166

Restricting Actions to Moderator167

Testing the Forum 168

Creating Test Fixtures 168

Creating the Functional Tests169

Further Development of the Discussion Foru175

Summary 176

■CHAPTER 6 Building a Blogging En178

with Web Services Suppor178

Specifying the Blog Engine Requirements 178

The Entry Model 178

The Comment Model179

The User Model179

The Entries Controller180

The Comments Controlle180

The Blogs Controller 180

Blogging APIs .180

Building the Blogging System181

Generating the Blogging Scaffolding Code181

Writing the Migrations 183

The Models’ Relationships and Validations185

Creating the Resource Mapping 186

The Blog Name Helper Metho186

Adding the Blog Title to the Edit User Profile Page 187

The Controllers and View188

Testing the Entries Controller196

Creating and Testing the Comments Controlle198

Adding the Latest Blog Entries to User Profiles 202

The Blogs Controller 203

Creating an XML-RPC Blogging Interface 205

Action Web Service 206

Generating the Web Service Code206

Defining the API Method Calls207

Writing the Blogging API Method Code 209

Testing the Web Service211

Testing Using a Desktop Blogging Client 211

Automated Testing of the Blogging AP213

Further Development of the Blogging System 214

Summary 214

■CHAPTER 7 Building a Photo Gallery 216

Working with Uploaded Files 216

The attachment_fu Plug-i217

The Photo Gallery Requirement219

Defining the Photo Model 220

The Photos Controllers 220

and attachment_fu .220

Installing on Windows 221

Installing on OS 221

Installing on Linu221

Installing the attachment_fu Plug-in221

Building the Photo Gallery 222

Generating the Scaffolding Cod222

Writing the Migration223

Creating the Photo Model and Its Relationship224

Mapping the Photos Resourc225

The Photos and User Photos Controllers 225

The Photo Views 228

Manually Testing the Gallery 233

Writing the Test Cases235

Creating the Photo Fixtures235

Unit Testin235

Functional Tests 237

Further Development of the Photo Gallery 240

Summary 240

■CHAPTER 8 Sending E-mail and Buil242

a Newsletter Mailing Lis242

Using ActionMailer .242

Configuring ActionMailer 242

Specifying the E-mail Feature Requirements 243

E-mail Notifications of New Comment244

E-mail Newsletters 244

Building the New Comment Notifier245

Creating the Mailer 245

Manually Testing E-mail Creatio248

Calling the Mailer from the Comments Controller251

Testing the Mailer from Within the Application 252

Automating the Mailer Tests 253

Building the Newsletter Featur255

Installing ar_mailer 255

Creating the Skeleton Resource 257

Mapping the Newsletter Resource258

The Newsletter Model 259

Writing the Newsletter Controller and Views 259

Creating the Newsletter Maile266

Add the Newsletters to the Sidebar .266

Testing the Newsletter Mailer267

Further Development of the E-mail System 269

Summary 269

■CHAPTER 9 Adding Friends with XFN Details 272

Microformats and XFN272

The Friends Feature Requirement274

The Friends Resource274

Showing Users’ Latest Activities 276

Building the Friends Resource276

Creating the Database Migrations276

Building the Friends Resourc279

Updating the User’s Latest Activity282

The Friends Controller and View283

Adding Friends Links to the Sidebar Menu 292

Styling the Friends List294

Testing 297

Further Development of the Friendship Feature 299

Summary 300

■CHAPTER 10 Adding Tags to the Photo Gallery 302

The Gallery Tagging Requirement302

Tagging with Rails .303

The acts_as_taggable_on_steroids Plug-in304

Building the Photo Tagging Feature307

Installing the acts_as_taggable_on_steroids Plug-307

Creating the Database Tables308

Updating the Models 309

Creating the Controller310

Adding the Resource Mappings 310

Writing the Controllers and View311

Adding Tags to a Phot315

Linking to the Tag Browser320

Manually Testing321

Further Development of the Tagging System 323

Summary 324

■CHAPTER 11 Creating Mashups and Integrating with Web 2.0 .326

Integrating the Google Maps AP326

The Mapping Feature Requirements327

Building the Mapping Feature328

Integrating the Flickr AP341

The Flickr Feature Requirement342

Building the Flickr Integration Feature 342

Further Development Using Mashups351

Summary 352

■CHAPTER 12 Adding User-Created Th354

to the Blogging Engine354

The Blog Template Requirements.354

Liquid Templates 355

The Liquid API .356

Liquid Markup .356

Installing Liqu357

Building the Blog Templates Featu358

Creating the Liquid Drop358

Creating the Liquid Filter361

The Usertemplate Model 362

The Usertemplates Controller363

The Usertemplate Views 365

Rendering Liquid Templates 367

Manual Testi368

Testing the Usertemplates Controll371

Further Development of the User Templates373

Summary 374

■CHAPTER 13 Adding a Mobile Interface.376

The Mobile Web376

The RailsCoders Mobile Site Requirements 377

The Layout 378

User Profiles379



News Articles379

Forums 379


Photo Gallery380

Developing Mobile RailsCoders 380

Structure of the Mobile Application .380

Creating the Mobile Layout and Style Sheet 381

The Resource Mappings 382

The Mobile Controllers and View385

Manual Testi400

Testing the Mobile Site 400

Further Development of the Mobile Site 402

Summary 402

■CHAPTER 14 Deploying, Optimizing, and Scaling the Application404

Deploying RailsCoders404

Development Mode vs. Production Mode 404

Session Storage 405

Choosing a Host 406

Choosing a Web Serve407

Automating Deployment with Capistrano and Deprec 408

Optimizing and Scaling RailsCoders417

Watching the Log Files 417


Benchmarking .420

Summary 421