提交 bcd22696 编写于 作者: V Vijay Dev

Merge branch 'master' of github.com:lifo/docrails

......@@ -38,7 +38,7 @@ def self.[](type)
# respond_to do |format|
# format.html
# format.ics { render :text => post.to_ics, :mime_type => Mime::Type["text/calendar"] }
# format.xml { render :xml => @people.to_xml }
# format.xml { render :xml => @people }
# end
# end
# end
......
......@@ -1004,7 +1004,7 @@ Scopes are also chainable within scopes:
<ruby>
class Post < ActiveRecord::Base
scope :published, -> { where(:published => true) }
scope :published_and_commented, -> { published.and(self.arel_table[:comments_count].gt(0)) }
scope :published_and_commented, -> { published.where("comments_count > 0") }
end
</ruby>
......
......@@ -42,7 +42,7 @@ h4. Install Git
Ruby on Rails uses git for source code control. The "git homepage":http://git-scm.com/ has installation instructions. There are a variety of resources on the net that will help you get familiar with git:
* "Everyday Git":http://www.kernel.org/pub/software/scm/git/docs/everyday.html will teach you just enough about git to get by.
* "Everyday Git":http://schacon.github.com/git/everyday.html will teach you just enough about git to get by.
* The "PeepCode screencast":https://peepcode.com/products/git on git ($9) is easier to follow.
* "GitHub":http://help.github.com offers links to a variety of git resources.
* "Pro Git":http://progit.org/book/ is an entire book about git with a Creative Commons license.
......
......@@ -866,19 +866,35 @@ The I18n API will catch all of these exceptions when they are thrown in the back
The reason for this is that during development you'd usually want your views to still render even though a translation is missing.
In other contexts you might want to change this behaviour, though. E.g. the default exception handling does not allow to catch missing translations during automated tests easily. For this purpose a different exception handler can be specified. The specified exception handler must be a method on the I18n module:
In other contexts you might want to change this behaviour, though. E.g. the default exception handling does not allow to catch missing translations during automated tests easily. For this purpose a different exception handler can be specified. The specified exception handler must be a method on the I18n module or a class with +#call+ method:
<ruby>
module I18n
def self.just_raise_that_exception(*args)
raise args.first
class JustRaiseExceptionHandler < ExceptionHandler
def call(exception, locale, key, options)
if exception.is_a?(MissingTranslation)
raise exception.to_exception
else
super
end
end
end
end
I18n.exception_handler = :just_raise_that_exception
I18n.exception_handler = I18n::JustRaiseExceptionHandler.new
</ruby>
This would re-raise all caught exceptions including +MissingTranslationData+.
This would re-raise only the +MissingTranslationData+ exception, passing all other input to the default exception handler.
However, if you are using +I18n::Backend::Pluralization+ this handler will also raise +I18n::MissingTranslationData: translation missing: en.i18n.plural.rule+ exception that should normally be ignored to fall back to the default pluralization rule for English locale. To avoid this you may use additional check for translation key:
<ruby>
if exception.is_a?(MissingTranslation) && key.to_s != 'i18n.plural.rule'
raise exception.to_exception
else
super
end
</ruby>
Another example where the default behaviour is less desirable is the Rails TranslationHelper which provides the method +#t+ (as well as +#translate+). When a +MissingTranslationData+ exception occurs in this context, the helper wraps the message into a span with the CSS class +translation_missing+.
......
......@@ -51,7 +51,7 @@ end
This migration adds a table called +products+ with a string column called +name+
and a text column called +description+. A primary key column called +id+ will
also be added, however since this is the default we do not need to ask for this.
also be added, however since this is the default we do not need to explicitly specify it.
The timestamp columns +created_at+ and +updated_at+ which Active Record
populates automatically will also be added. Reversing this migration is as
simple as dropping the table.
......@@ -65,7 +65,7 @@ class AddReceiveNewsletterToUsers < ActiveRecord::Migration
change_table :users do |t|
t.boolean :receive_newsletter, :default => false
end
User.update_all ["receive_newsletter = ?", true]
User.update_all :receive_newsletter => true
end
def down
......@@ -635,10 +635,9 @@ example,
$ rake db:migrate:up VERSION=20080906120000
</shell>
will run the +up+ method from the 20080906120000 migration. These tasks still
check whether the migration has already run, so for example +db:migrate:up
VERSION=20080906120000+ will do nothing if Active Record believes that
20080906120000 has already been run.
will run the +up+ method from the 20080906120000 migration. This task will first
check whether the migration is already performed and will do nothing if Active Record believes
that it has already been run.
h4. Changing the output of running migrations
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册