Recipe 15.1. Writing a Simple Rails Application to Show System Status
Problem
You would like to get started with Rails by building a very simple application.
Solution
This example displays the running processes on a Unix
system. I...
Recipe 15.2. Passing Data from the Controller to the View
Problem
You want to pass data between a controller and its views.
Solution
The view is an ERB template that is interpreted within the context of its controller object. A view ...
Recipe 15.3. Creating a Layout for Your Header and Footer
Problem
You want to create a header and footer for every page on your web application. Certain pages should have special headers and
footers, and you may want to dynami...
Recipe 15.4. Redirecting to a Different Location
Problem
You want to redirect your user to another of your application's actions, or to an external URL.
Solution
The class ActionController::Base (superclass of ApplicationController) defin...
Recipe 15.5. Displaying Templates with Render
Problem
Rails's default mapping of one action method to one view template is not flexible enough for you. You want to customize the template that gets rendered for a particular action by callin...
Recipe 15.6. Integrating a Database with Your Rails Application
Problem
You want your web application to store persistent data in a relational database.
Solution
The hardest part is setting things up: creating your database and ...
Recipe 15.7. Understanding Pluralization Rules
Problem
You want to understand and customize Rails's rules for automatically pluralizing nouns.
Solution
You can use Rails'
pluralization functionality in any part of your application...
Recipe 15.8. Creating a Login System
Problem
You want your application to support a login system based on user accounts. Users will log in with a unique username and password, as in most commercial and community web sites.
Solution
C...
Recipe 15.9. Storing Hashed User Passwords in the Database
Problem
The database table defined in Recipe 15.8 stores users' passwords as plain text. This is a bad idea: if someone compromises the database, she will have all of your users' passwo...
Recipe 15.10. Escaping HTML and JavaScript for Display
Problem
You want to display data that might contain HTML or JavaScript without making browsers render it as HTML or interpret the JavaScript. This is especially important when dis...
Recipe 15.11. Setting and Retrieving Session Information
Problem
You want to associate some data with each distinct web client that's using your application. The data needs to persist across HTTP requests.
Solution
You can use cookies (se...
Recipe 15.12. Setting and Retrieving Cookies
Problem
You want to set a cookie from within Rails.
Solution
Recall from Recipe 15.11 that all Rails controllers, views, helpers, and mailers have access to a method called sessions that r...
Recipe 15.13. Extracting Code into Helper Functions
Problem
Your views are getting cluttered with Ruby
code.
Solution
Let's create a controller with a fairly complex view to see how this can happen:
$ ./scripts/gener...
Recipe 15.14. Refactoring the View into Partial Snippets of Views
Problem
Your view doesn't contain a lot of Ruby code, but it's still becoming more complicated than you'd like. You'd like to refactor the view logic into separate, reusable temp...
Recipe 15.15. Adding DHTML Effects with script.aculo.us
Problem
You want to add fancy effects such as fades to your application, without writing any JavaScript.
Solution
Every
Rails application comes bundled with some JavaScr...
Recipe 15.16. Generating Forms for Manipulating Model Objects
Problem
You want to define actions that let a user create or edit objects stored in the database.
Solution
Let's create a simple model, and then build forms for it. H...
Recipe 15.17. Creating an Ajax Form
Problem
You want to build a web application that's responsive and easy to use. You don't want your users to spend lots of time waiting around for the browser to redraw the screen.
Solution
You can use J...
Recipe 15.18. Exposing Web Services on Your Web Site
Problem
You want to offer
SOAP and
XML-RPC web services from your web application.
Solution
Rails comes with a built-in web service generator that makes it easy to expose a con...
Recipe 15.19. Sending Mail with Rails
Problem
You want to send an
email from within your Rails application: perhaps a confirmation of an order, or notification that some action has been taken on a user's behalf.
Solution
The first is t...
Recipe 15.20. Automatically Sending Error Messages to Your Email
Problem
You want to receive a descriptive email message every time one of your users encounters an application error.
Solution
Any
errors that occur while running your ap...
Recipe 15.21. Documenting Your Web Site
Problem
You want to document the controllers, models, and helpers of your web application so that the developers responsible for maintaining the application can understand how it works.
Solution...
Recipe 15.22. Unit Testing Your Web Site
Problem
You want to create a suite of automated tests that test the functionality of your Rails application.
Solution
Rails can't write your test code any more than it can write your view...
AJAX popular information C# language guides Windows books and cookbooks
.......
С 2009 года мы стали переводить структура сайта на различные языки. Сайт теперь будет содержать книги не только на английском языке, но также и на других европейских языках, в том числе и на Русском языке.