skip to content
The Rails way Preview this item
ClosePreview this item
Checking...

The Rails way

Author: Obie Fernandez
Publisher: Upper Saddle River, NJ : Addison-Wesley, ©2008.
Series: Addison-Wesley professional Ruby series.
Edition/Format:   Print book : EnglishView all editions and formats
Summary:

Designed for professional application developers and programmers wanting to move beyond basic knowledge of Ruby on Rails, this text helps readers attain the productivity and code elegance achieved by  Read more...

Rating:

(not yet rated) 0 with reviews - Be the first.

Subjects
More like this

 

Find a copy in the library

&AllPage.SpinnerRetrieving; Finding libraries that hold this item...

Details

Material Type: Internet resource
Document Type: Book, Internet Resource
All Authors / Contributors: Obie Fernandez
ISBN: 0321445619 9780321445612
OCLC Number: 173509399
Description: lix, 851 pages ; 24 cm.
Contents: Chapter 1: Rails Environment and Configurations 1Startup 2 Default Environment Settings 2 Bootstrapping 3 RubyGems 5 Initializer 6 Default Load Paths 6 Rails, Modules, and Auto-Loading Code 7 Builtin Rails Info 8 Configuration 9 Additional Configuration 13Development Mode 14 Automatic Class Reloading 15 The Rails Class Loader 15Test Mode 17Production Mode 17Logging 18 Rails Log Files 20 Log File Analysis 22Syslog 24Conclusion 25References 25 Chapter 2 Working with Controllers 27The Dispatcher: Where It All Begins 28 Request Handling 28 Getting Intimate with the Dispatcher 29Render unto View... 31 When in Doubt, Render 32 Explicit Rendering 33 Rendering Another Action's Template 33 Rendering a Different Template Altogether 34 Rendering a Partial Template 35 Rendering Inline Template Code 35 Rendering Text 35 Rendering Other Types of Structured Data 36 Rendering Nothing 36 Rendering Options 37Redirecting 39Controller/View Communication 42Filters 43 Filter Inheritance 44 Filter Types 46 Filter Chain Ordering 47 Around Filters 48 Filter Chain Skipping 49 Filter Conditions 50 Filter Chain Halting 50Streaming 51 send_data(data, options = {}) 51 send_file(path, options = {}) 52 Letting the Web Server Send Files 55Conclusion 56References 56 Chapter 3 Routing 57The Two Purposes of Routing 58Bound Parameters 60Wildcard Components ("Receptors") 61Static Strings 62The routes.rb File 63 The Default Route 65 Spotlight on the :id Field 66 Default Route Generation 67 Modifying the Default Route 68The Ante-Default Route and respond_to 69 respond_to and the HTTP-Accept Header 70The Empty Route 71Writing Custom Routes 72Using Static Strings 72Using Your Own "Receptors" 73A Note on Route Order 75Using Regular Expressions in Routes 76Default Parameters and the url_for Method 76 What Happened to :id? 77Using Literal URLs 79Route Globbing 79Globbing Key-Value Pairs 80Named Routes 81 Creating a Named Route 81 The Question of Using name_path Versus name_url 82 Considerations 83What to Name Your Routes 83 Argument Sugar 84 A Little More Sugar with Your Sugar? 85The Special Scope Method with_options 86Conclusion 88References 88 Chapter 4 REST, Resources, and Rails 89REST in a Rather Small Nutshell 89REST in Rails 91Routing and CRUD 92Resources and Representations 93 REST Resources and Rails 93 From Named Routes to REST Support 94 Reenter the HTTP Verb 96The Standard RESTful Controller Actions 96 The PUT and DELETE Cheat 98 Singular and Plural RESTful Routes 98 The Special Pairs: new/create and edit/update 99Singular Resource Routes 100Nested Resources 101 Setting :path_prefix Explicitly 103 Setting :name_prefix Explicitly 103 Specifying RESTful Controllers Explicitly 105 All Together Now 105 Considerations 107 Deep Nesting? 108RESTful Route Customizations 110 Extra Member Routes 110 Extra Collection Routes 111 Considerations 112Controller-Only Resources 113Different Representations of Resources 115 The respond_to Method 116 Formatted Named Routes 117The RESTful Rails Action Set 117 Index 118 Show 121 Destroy 121 New and Create 123 Edit and Update 124Conclusion 125Reference 126 Chapter 5 Reflecting on Rails Routing 127Examining Routes in the Application Console 127 Dumping Routes 128 Anatomy of a Route Object 129 Recognition and Generation in the Console 132 Named Routes in the Console 134Testing Routes 135The Routing Navigator Plugin 136Conclusion 137References 137 Chapter 6 Working with ActiveRecord 139The Basics 140Migrations 142 Creating Migrations 143Naming Migrations 144Migration Pitfalls 145 Migration API 146 Defining Columns 149Macro-Style Methods 155 Relationship Declarations 155 Convention over Configuration 156 Pluralization 157 Setting Names Manually 158 Legacy Naming Schemes 159Defining Attributes 160 Default Attribute Values 160 Serialized Attributes 162CRUD: Creating, Reading, Updating, Deleting 163 Creating New ActiveRecord Instances 163 Reading ActiveRecord Objects 164 Reading and Writing Attributes 166 Accessing and Manipulating Attributes Before They Are Typecast 168 Reloading 169 Dynamic Attribute-Based Finders 169 Custom SQL Queries 171 The Query Cache 172 Updating 174 Updating by Condition 176 Updating a Particular Instance 176 Updating Specific Attributes 177 Convenience Updaters 177 Controlling Access to Attributes 178 Deleting and Destroying 178Database Locking 179 Optimistic Locking 180 Pessimistic Locking 182 Considerations 183Advanced Finding 183 Conditions 183 Ordering of Find Results 186 Limit and Offset 186 Select Option 187 From Option 188 Group By Option 188 Locking Option 189 Joining and Including Associations 189 Read Only 189Connections to Multiple Databases in Different Models 189Using the Database Connection Directly 191 The DatabaseStatements Module 191 Other Connection Methods 194Other Configuration Options 196Conclusion 197References 198 Chapter 7 ActiveRecord Associations 199The Association Hierarchy 199One-to-Many Relationships 201 Adding Associated Objects to a Collection 203 AssociationCollection Methods 204The belongs_to Association 207 Reloading the Association 208 Building and Creating Related Objects via the Association 208 belongs_to Options 209The has_many Association 215 has_many Options 216 Proxy Methods 224Many-to-Many Relationships 225 has_and_belongs_to_many 225 has_many :through 233 has_many :through Options 238:source 238One-to-One Relationships 241 has_one 241 has_one Options 244:Unsaved Objects and Associations 246 One-to-One Associations 246 Collections 247Association Extensions 247The AssociationProxy Class 249reload and reset 249proxy_owner, proxy_reflection, and proxy_target 249Conclusion 250References 251 Chapter 8 ActiveRecord Validations 253Finding Errors 253The Simple Declarative Validations 254 validates_acceptance_of 254 validates_associated 255 validates_confirmation_of 256 validates_each 256 validates_inclusion_of and validates_exclusion_of 257 validates_existence_of 257 validates_format_of 258 validates_length_of 259 validates_numericality_of 260 validates_presence_of 261 validates_uniqueness_of 261RecordInvalid 263Common Validation Options 263 :allow_nil 263 :if 263 :message 263 :on 264Conditional Validation 264 Usage and Considerations 265Working with the Errors Object 266 Manipulating the Errors Collection 267 Checking for Errors 267Custom Validation 268Skipping Validations 269Conclusion 270Reference 270 Chapter 9 Advanced ActiveRecord 271Callbacks 271 Callback Registration 272 Matched before/after Callbacks 274 Halting Execution 274 Callback Usages 275 Special Callbacks: after_initialize and after_find 278 Callback Classes 279Observers 282 Naming Conventions 283 Registration of Observers 283 Timing 284Single-Table Inheritance (STI) 284 Mapping Inheritance to the Database 286 STI Considerations 288 STI and Associations 288Abstract Base Model Classes 291Polymorphic has_many Relationships 292 In the Case of Models with Comments 293 Considerations about has_many 296Modules for Reusing Common Behavior 296 A Review of Class Scope and Contexts 299 The included Callback 300Modifying ActiveRecord Classes at Runtime 301 Considerations 303 Ruby and Domain-Specific Languages 303Conclusion 305References 305 Chapter 10 ActionView 307ERb Basics 308 ERb Practice 308 Tightening Up ERb Output 310 Commenting Out ERb Delimiters 310 Conditional Output 311 RHTML? RXML? RJS? 311Layouts and Templates 312 Yielding Content 313 Template Variables 315 Protecting the Integrity of Your View from User-Submitted Content 319Partials 320 Simple Use Cases 321 Reuse of Partials 322 Shared Partials 323 Passing Variables to Partials 324 Render Collections 325 Logging 327 Caching 327 Caching in Development Mode? 328 Page Caching 328 Action Caching 328 Fragment Caching 330 Expiration of Cached Content 333 Automatic Cache Expiry with Sweepers 335 Cache Logging 337 Action Cache Plugin 337 Cache Storage 338Conclusion 340References 340 Chapter 11 All About Helpers 341ActiveRecordHelper 342 Reporting Validation Errors 342 Automatic Form Creation 344 Customizing the Way Validation Errors Are Highlighted 346AssetTagHelper 348 Head Helpers 348 For Plugins Only, Add Default JavaScript Includes 352BenchmarkHelper 353benchmark(message = "Benchmarking", level = :info) 353CacheHelper 353CaptureHelper 354capture(&block) 354content_for(name, &block) 354DateHelper 355 The Date and Time Selection Helpers 355 The Individual Date and Time Select Helpers 356 Common Options for Date Selection Helpers 359 distance_in_time Methods with Complex Descriptive Names 359DebugHelper 361FormHelper 362 Creating Forms for ActiveRecord Models 362 How Form Helpers Get Their Values 370FormOptionsHelper 371 Select Helpers 371 Option Helpers 373FormTagHelper 378check_box_tag(name, value = "1", checked = false, options = {}) 378end_form_tag 378file_field_tag(name, options = {}) 378form_tag(url_for_options = {}, options = {}, *parameters_for_url, &block) 379hidden_field_tag(name, value = nil, options = {}) 380image_submit_tag(source, options = {}) 380password_field_tag(name = "password", value = nil, options = {}) 380radio_button_tag(name, value, checked = false, options = {}) 380select_tag(name, option_tags = nil, options = {}) 380start_form_tag 380submit_tag(value = "Save changes", options = {}) 381text_area_tag(name, content = nil, options = {}) 381text_field_tag(name, value = nil, options = {}) 381JavaScriptHelper 381button_to_function(name, function, html_options={}, &block) 381define_javascript_functions() 382escape_javascript(javascript) 382javascript_tag(content, html_options={}) 382link_to_function(name, function, html_options={}, &block) 382NumberHelper 383human_size(size, precision=1) 383number_to_currency(number, options = {}) 383number_to_human_size(size, precision=1) 384number_to_percentage(number, options = {}) 384number_to_phone(number, options = {}) 385number_with_delimiter(number, delimiter=",", separator=".") 385number_with_precision(number, precision=3) 385 PaginationHelper 386 will_paginate 386 paginator 387 Paginating Find 388RecordIdentificationHelper 388dom_class(record_or_class, prefix = nil) 389dom_id(record, prefix = nil) 389partial_path(record_or_class) 389RecordTagHelper 390content_tag_for(tag_name, record, *args, &block) 390div_for(record, *args, &block) 391TagHelper 391cdata_section(content) 391content_tag(name, content = nil, options = nil, &block) 391escape_once(html) 392tag(name, options = nil, open = false) 392TextHelper 393auto_link(text, link = :all, href_options = {}, &block) 393concat(string, binding) 393cycle(first_value, *values) 394excerpt(text, phrase, radius = 100, excerpt_string = "...") 395highlight(text, phrases, highlighter = `\1') 395markdown(text) 396pluralize(count, singular, plural = nil) 396reset_cycle(name = "default") 397sanitize(html) 397simple_format(text) 398strip_links(text) 398strip_tags(html) 398textilize(text) 399textilize_without_paragraph(text) 399truncate(text, length = 30, truncate_string = "...") 399word_wrap(text, line_width = 80) 400UrlHelper 400button_to(name, options = {}, html_options = {}) 400current_page?(options) 401link_to(name, options = {}, html_options = nil) 401link_to_if(condition, name, options = {}, html_options = {}, &block) 403link_to_unless(condition, name, options = {}, html_options = {}, &block) 403link_to_unless_current(name, options = {}, html_options = {}, &block) 403mail_to(email_address, name = nil, html_options = {}) 404url_for(options = {}) 405Relying on Named Routes 406Writing Your Own Helpers 407 Small Optimizations: The Title Helper 407 Encapsulating View Logic: The photo_for Helper 408 Smart View: The breadcrumbs Helper 409 Wrapping and Generalizing Partials 410 A tiles Helper 410 Generalizing Partials 414Conclusion 417References 417 Chapter 12 Ajax on Rails 419Prototype 420 FireBug 421 The Prototype API 421 Top-Level Functions 422 Class 424 Extensions to JavaScript's Object Class 425 Extensions to JavaScript's Array Class 426 Extensions to the document Object 428 Extensions to the Event Class 428 Extensions to JavaScript's Function Class 430 Extensions to JavaScript's Number Class 432 Extensions to JavaScript's String class 433string.dasherize() 434string.escapeHTML() and string.unescapeHTML() 434string.evalScripts() and string.extractScripts() 434string.gsub(pattern, replacement) and string.sub(pattern, replacement, count) 434string.scan(pattern, iterator) 434string.strip() 435string.stripScripts() and string.stripTags() 435string.parseQuery() and string.toQueryParams() 435string.toArray() 435string.truncate(length, truncationString) 435string.underscore() 436 The Ajax Object 436 Ajax.Responders 437 Enumerable 437 Hash 443 ObjectRange 444 The Prototype Object 445The PrototypeHelper Module 445 link_to_remote 445 remote_form_for 449 periodically_call_remote 451 observe_field 451 observe_form 453RJS-Writing Javascript in Ruby 453 RJS Templates 455 <<(javascript) 456 [](id) 457 alert(message) 457 call(function, *arguments, &block) 457 delay(seconds = 1) { ... } 458 draggable(id, options = {}) 458 drop_receiving(id, options = {}) 458 hide(*ids) 458 insert_html(position, id, *options_for_render) 458 literal(code) 459 redirect_to(location) 459 remove(*ids) 459 replace(id, *options_for_render) 460 replace_html(id, *options_for_render) 460 select(pattern) 460 show(*ids) 460 sortable(id, options = {}) 460 toggle(*ids) 461 visual_effect(name, id = nil, options = {}) 461JSON 461Drag and Drop 46300_5619_fm.qxd 10/25/07 4:05 PM Page xxxiiSortable 465Autocompleter 466In-Place Editors 467Conclusion 467References 468 Chapter 13 Session Management 469What to Store in the Session 470 The Current User 470 Session Use Guidelines 470 Session Options 471 Disabling Sessions for Robots 472 Selectively Enabling Sessions 473 Secure Sessions 473Storage Mechanisms 473 ActiveRecord SessionStore 473 PStore (File-Based) 474 DRb Session Storage 475 memcache Session Storage 475 The Controversial CookieStore 476Timing Out and Session Life Cycle 478 Session Timeout Plugin for Rails 478 Tracking Active Sessions 479 Enhanced Session Security 480 Cleaning Up Old Sessions 481Cookies 481 Reading and Writing Cookies 482Conclusion 483References 483 Chapter 14 Login and Authentication 485Acts as Authenticated 486 Installation and Setup 486 The User Model 487 The Account Controller 496 Login from Cookie 498 The Current User 499Logging In During Testing 501Conclusion 502References 502 Chapter 15 XML and ActiveResource 503The to_xml Method 503 Customizing to_xml Output 505 Associations and to_xml 507 Advanced to_xml 508 Dynamic Runtime Attributes 509 Overriding to_xml 510 Learning from Array's to_xml Method 510The XML Builder 513Parsing XML 515 Turning XML into Hashes 515 XmlSimple 516 Typecasting 518ActiveResource 519Find 519 Create 522 Update 524 Delete 524 Headers 526 Customizing 527 Hash Forms 528Conclusion 529 Chapter 16 ActionMailer 531Setup 531Mailer Models 532 Preparing Outbound Email Messages 533 HTML Email Messages 536 Multipart Messages 537 File Attachments 539 Actually Sending an Email 540Receiving E-Mails 540 TMail::Mail API Reference 541 Handling Attachments 543Configuration 543Conclusion 544References 544 Chapter 17 Testing 545Rails Testing Terminology 546 So Much for Isolation... 547 Rails Mocks? 548 Real Mocks and Stubs 549 Integration Tests 550 Dealing with the Confusion 551Test::Unit 552 Running Tests 553Fixtures 554 CSV Fixtures 555 Accessing Fixture Records from Tests 556 Dynamic Fixture Data 556 Using Fixture Data in Development Mode 557 Generating Fixtures from Development Data 558 Fixtures Options 559 Everybody Hates Fixtures 560 Fixtures Really Aren't That Bad 562Assertions 562 Basic Assertions 562 Rails Assertions 566 One Assertion per Test Method 566Testing Models with Unit Tests 568 Model Testing Basics 568 Deciding What to Test 570Testing Controllers with Functional Tests 570 Structure and Setup 570 Functional Test Methods 571 Common Assertions 572Testing Views with Functional Tests 576assert_select(selector, [*values, equality, message, &block]) 577assert_select(element, selector, [*values, equality, message, &block]) 577Optional Block Parameter 577Selector Reference 578Equality Tests 580 Testing RJS Behavior 581 Other Selection Methods 582 Testing Routing Rules 582Rails Integration Tests 584 Basics 584 The Integration Test API 585 Working with Sessions 586Rake Tasks Related to Testing 587Acceptance Tests 588 Acceptance Test First? 588Selenium 589 Basics 589 Getting Started 591RSelenese 592Conclusion 593References 594 Chapter 18 RSpec on Rails 597Introduction to RSpec 597 Should and Expectations 598 Predicates 599 Custom Expectation Matchers 601 Multiple Examples per Behavior 603 Shared Behaviors 604 RSpec's Mocks and Stubs 607 Running Specs 610 Installing RSpec and the RSpec on Rails Plugin 613The RSpec on Rails Plugin 613 Generators 614 Model Specs 614 Controller Specs 617 View Specs 621 Helper Specs 623 Scaffolding 623RSpec Tools 624 Autotest 624 RCov 624Conclusion 625References 626 Chapter 19 Extending Rails with Plugins 627Managing Plugins 628 Reusing Code 628T he Plugin Script 629 Subversion and script/plugin 633Using Piston 636 Installation 636 Importing a Vendor Library 637 Converting Existing Vendor Libraries 638 Updating 638 Locking and Unlocking Revisions 639 Piston Properties 639Writing Your Own Plugins 640 The init.rb Hook 640 The lib Directory 642 Extending Rails Classes 643 The README and MIT-LICENSE File 644 The install.rb and uninstall.rb Files 645 Custom Rake Tasks 647 The Plugin's Rakefile 648 Testing Plugins 649Conclusion 649References 650 Chapter 20 Rails Production Configurations 651A Brief History of Rails In Production 652Some Basic Prerequisites 652The Stack Checklist 654 Server and Network Environment 655 Web Tier 656 Application Tier 656 Database Tier 656 Monitoring 657 Version Control 657Installations 657 Ruby 658 RubyGems 658 Rails 659 Mongrel 659 Mongrel Cluster 659 Nginx 659 Subversion 660 MySQL 660 Monit 661 Capistrano 661Configurations 661 Configuring Mongrel Cluster 662 Configuring Nginx 663 Configuring Monit 667 Configuring Capistrano 670
Series Title: Addison-Wesley professional Ruby series.
Responsibility: Obie Fernandez.
More information:

Reviews

User-contributed reviews
Retrieving GoodReads reviews...
Retrieving DOGObooks reviews...

Tags

Be the first.
Confirm this request

You may have already requested this item. Please select Ok if you would like to proceed with this request anyway.

Linked Data


Primary Entity

<http://www.worldcat.org/oclc/173509399> # The Rails way
    a schema:CreativeWork, schema:Book ;
   library:oclcnum "173509399" ;
   library:placeOfPublication <http://experiment.worldcat.org/entity/work/data/103147611#Place/upper_saddle_river_nj> ; # Upper Saddle River, NJ
   library:placeOfPublication <http://id.loc.gov/vocabulary/countries/nju> ;
   schema:about <http://id.worldcat.org/fast/1042804> ; # Object-oriented programming (Computer science)
   schema:about <http://id.worldcat.org/fast/811707> ; # Application software--Development
   schema:about <http://dewey.info/class/005.117/e22/> ;
   schema:about <http://experiment.worldcat.org/entity/work/data/103147611#CreativeWork/ruby_on_rails_electronic_resource> ; # Ruby on rails (Electronic resource)
   schema:about <http://id.worldcat.org/fast/1101038> ; # Ruby (Computer program language)
   schema:about <http://id.worldcat.org/fast/1173243> ; # Web site development
   schema:about <http://id.worldcat.org/fast/1791554> ; # Ruby on rails (Electronic resource)
   schema:about <http://id.loc.gov/authorities/subjects/sh95009362> ; # Application software--Development
   schema:bookFormat bgn:PrintBook ;
   schema:copyrightYear "2008" ;
   schema:creator <http://viaf.org/viaf/70845450> ; # Obie Fernandez
   schema:datePublished "2008" ;
   schema:exampleOfWork <http://worldcat.org/entity/work/id/103147611> ;
   schema:inLanguage "en" ;
   schema:isPartOf <http://experiment.worldcat.org/entity/work/data/103147611#Series/addison_wesley_professional_ruby_series> ; # Addison-Wesley professional Ruby series.
   schema:name "The Rails way"@en ;
   schema:productID "173509399" ;
   schema:publication <http://www.worldcat.org/title/-/oclc/173509399#PublicationEvent/upper_saddle_river_nj_addison_wesley_2008> ;
   schema:publisher <http://experiment.worldcat.org/entity/work/data/103147611#Agent/addison_wesley> ; # Addison-Wesley
   schema:url <http://catdir.loc.gov/catdir/toc/ecip081/2007039880.html> ;
   schema:workExample <http://worldcat.org/isbn/9780321445612> ;
   wdrs:describedby <http://www.worldcat.org/title/-/oclc/173509399> ;
    .


Related Entities

<http://experiment.worldcat.org/entity/work/data/103147611#CreativeWork/ruby_on_rails_electronic_resource> # Ruby on rails (Electronic resource)
    a schema:CreativeWork ;
   schema:name "Ruby on rails (Electronic resource)" ;
    .

<http://experiment.worldcat.org/entity/work/data/103147611#Place/upper_saddle_river_nj> # Upper Saddle River, NJ
    a schema:Place ;
   schema:name "Upper Saddle River, NJ" ;
    .

<http://experiment.worldcat.org/entity/work/data/103147611#Series/addison_wesley_professional_ruby_series> # Addison-Wesley professional Ruby series.
    a bgn:PublicationSeries ;
   schema:hasPart <http://www.worldcat.org/oclc/173509399> ; # The Rails way
   schema:name "Addison-Wesley professional Ruby series." ;
   schema:name "Addison-Wesley professional Ruby series" ;
    .

<http://id.loc.gov/authorities/subjects/sh95009362> # Application software--Development
    a schema:Intangible ;
   schema:name "Application software--Development"@en ;
    .

<http://id.worldcat.org/fast/1042804> # Object-oriented programming (Computer science)
    a schema:Intangible ;
   schema:name "Object-oriented programming (Computer science)"@en ;
    .

<http://id.worldcat.org/fast/1101038> # Ruby (Computer program language)
    a schema:Intangible ;
   schema:name "Ruby (Computer program language)"@en ;
    .

<http://id.worldcat.org/fast/1173243> # Web site development
    a schema:Intangible ;
   schema:name "Web site development"@en ;
    .

<http://id.worldcat.org/fast/1791554> # Ruby on rails (Electronic resource)
    a schema:CreativeWork ;
   schema:name "Ruby on rails (Electronic resource)" ;
    .

<http://id.worldcat.org/fast/811707> # Application software--Development
    a schema:Intangible ;
   schema:name "Application software--Development"@en ;
    .

<http://viaf.org/viaf/70845450> # Obie Fernandez
    a schema:Person ;
   schema:familyName "Fernandez" ;
   schema:givenName "Obie" ;
   schema:name "Obie Fernandez" ;
    .

<http://worldcat.org/isbn/9780321445612>
    a schema:ProductModel ;
   schema:isbn "0321445619" ;
   schema:isbn "9780321445612" ;
    .


Content-negotiable representations

Close Window

Please sign in to WorldCat 

Don't have an account? You can easily create a free account.