1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

copy editing

This commit is contained in:
Vijay Dev 2011-10-05 18:40:45 +05:30
parent 34ed93931d
commit ea49935a6e
3 changed files with 6 additions and 9 deletions

View file

@ -1192,13 +1192,11 @@ h4. Creating Observers
For example, imagine a +User+ model where we want to send an email every time a new user is created. Because sending emails is not directly related to our model's purpose, we should create an observer to contain the code implementing this functionality.
Rails can create the initial code of the observers in a simple way. For instance, given a model +User+, the command
<shell>
$ rails generate observer User
</shell>
generates file +app/models/user_observer.rb+ containing the observer class +UserObserver+:
generates +app/models/user_observer.rb+ containing the observer class +UserObserver+:
<ruby>
class UserObserver < ActiveRecord::Observer

View file

@ -705,7 +705,7 @@ $ rails console
TIP: The default console will make changes to your database. You can instead
open a console that will roll back any changes you make by using <tt>rails console
--sandbox</tt> .
--sandbox</tt>.
After the console loads, you can use it to work with your application's models:
@ -1074,7 +1074,7 @@ In the +update+ action, Rails first uses the +:id+ parameter passed back from
the edit view to locate the database record that's being edited. The
+update_attributes+ call then takes the +post+ parameter (a hash) from the request
and applies it to this record. If all goes well, the user is redirected to the
post's +show+ action. If there are any problems, it's back to the +edit+ action to
post's +show+ action. If there are any problems, it redirects back to the +edit+ action to
correct them.
h4. Destroying a Post
@ -1115,8 +1115,7 @@ models and controllers. To create the new model, run this command in your
terminal:
<shell>
$ rails generate model Comment commenter:string body:text \
> post:references
$ rails generate model Comment commenter:string body:text post:references
</shell>
This command will generate four files:
@ -1520,7 +1519,7 @@ defined it as an instance variable.
h3. Deleting Comments
Another important feature of a blog is being able to delete SPAM comments. To do
Another important feature of a blog is being able to delete spam comments. To do
this, we need to implement a link of some sort in the view and a +DELETE+ action
in the +CommentsController+.

View file

@ -658,7 +658,7 @@ In many ways this is exactly what it is. This file is created by inspecting the
There is however a trade-off: +db/schema.rb+ cannot express database specific items such as foreign key constraints, triggers, or stored procedures. While in a migration you can execute custom SQL statements, the schema dumper cannot reconstitute those statements from the database. If you are using features like this, then you should set the schema format to +:sql+.
Instead of using Active Record's schema dumper, the database's structure will be dumped using a tool specific the RDBMS of the database (via the +db:structure:dump+ Rake task) into +db/#{Rails.env}_structure.sql+. For example, for the PostgreSQL RDBMS, the +pg_dump+ utility is used. For MySQL, this file will contain the output of +SHOW CREATE TABLE+ for the various tables. Loading these schemas is simply a question of executing the SQL statements they contain. By definition, this will create a perfect copy of the database's structure. Using the +:sql+ schema format will, however, prevent loading the schema into a RDBMS other than the one used to create it.
Instead of using Active Record's schema dumper, the database's structure will be dumped using a tool specific to the database (via the +db:structure:dump+ Rake task) into +db/#{Rails.env}_structure.sql+. For example, for the PostgreSQL RDBMS, the +pg_dump+ utility is used. For MySQL, this file will contain the output of +SHOW CREATE TABLE+ for the various tables. Loading these schemas is simply a question of executing the SQL statements they contain. By definition, this will create a perfect copy of the database's structure. Using the +:sql+ schema format will, however, prevent loading the schema into a RDBMS other than the one used to create it.
h4. Schema Dumps and Source Control