From e59b66979236c93b42467f5656da28179db1397c Mon Sep 17 00:00:00 2001 From: Sandip Ransing Date: Fri, 6 Apr 2012 00:44:56 +0530 Subject: Improvement to migration guide --- guides/source/migrations.textile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'guides/source') diff --git a/guides/source/migrations.textile b/guides/source/migrations.textile index 28426de6d7..1d8c1e03f3 100644 --- a/guides/source/migrations.textile +++ b/guides/source/migrations.textile @@ -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 write for this. 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,10 @@ example, $ rake db:migrate:up VERSION=20080906120000 -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, so for example + +db:migrate:up VERSION=20080906120000+ will do nothing if Active Record believes + that 20080906120000 has already been run. h4. Changing the output of running migrations -- cgit v1.2.3 From b11113f924d2eb2acbe836954d17a02163f45275 Mon Sep 17 00:00:00 2001 From: Sandip Ransing Date: Fri, 6 Apr 2012 01:11:42 +0530 Subject: Where migration can get wrong help added --- guides/source/migrations.textile | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'guides/source') diff --git a/guides/source/migrations.textile b/guides/source/migrations.textile index 1d8c1e03f3..a565974227 100644 --- a/guides/source/migrations.textile +++ b/guides/source/migrations.textile @@ -928,3 +928,13 @@ features, the +execute+ method can be used to execute arbitrary SQL. You could also use some plugin like "foreigner":https://github.com/matthuhiggins/foreigner which add foreign key support to Active Record (including support for dumping foreign keys in +db/schema.rb+). + +h3. Where you may get into trouble ? + +While running specific migrations with VERSION specified, By mistake if you misspell +command you may get into big trouble. + +Consider scenario where you want to run down migration +db:migrate:down VERSION=324213490000+ +By mistake if you type something like +db:migrate :down VERSION=324213490000+ then it will +change the complete meaning of migration command and it will be migrated like you are +executing +db:migrate VERSION=32421349000+ -- cgit v1.2.3 From 74fa0d3db0c364f91d8a9a8ab0741d5787531890 Mon Sep 17 00:00:00 2001 From: "xyctka@gmail.com" Date: Fri, 6 Apr 2012 10:01:34 +0100 Subject: Update Custom Exception Handler section of Internationalization guide The previous example with just_raise_that_exception method stopped working because MissingTranslation is not an instance of Exception class any more, but has a +to_exception+ method. Also the cleaner way is to re-raise only the desired exception, passing everything else to the default ExceptionHandler. Additionally this re-raising conflicts with Pluralization backend thus we have to add a check that certain missing translation keys should be ignored allowing the backend to fall back to the default pluralization rule. --- guides/source/i18n.textile | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'guides/source') diff --git a/guides/source/i18n.textile b/guides/source/i18n.textile index 320f1e9d20..89d67e1f92 100644 --- a/guides/source/i18n.textile +++ b/guides/source/i18n.textile @@ -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: module I18n - def self.just_raise_that_exception(*args) - raise args.first + class JustRaiseHandler < 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::JustRaiseHandler.new -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: + + +if exception.is_a?(MissingTranslation) && key.to_s != 'i18n.plural.rule' + raise exception.to_exception +else + super +end + 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+. -- cgit v1.2.3 From 5890ced113a63687b8ede0440ee3331449efe0af Mon Sep 17 00:00:00 2001 From: "xyctka@gmail.com" Date: Fri, 6 Apr 2012 10:04:26 +0100 Subject: Better class name --- guides/source/i18n.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'guides/source') diff --git a/guides/source/i18n.textile b/guides/source/i18n.textile index 89d67e1f92..6179694c40 100644 --- a/guides/source/i18n.textile +++ b/guides/source/i18n.textile @@ -870,7 +870,7 @@ In other contexts you might want to change this behaviour, though. E.g. the defa module I18n - class JustRaiseHandler < ExceptionHandler + class JustRaiseExceptionHandler < ExceptionHandler def call(exception, locale, key, options) if exception.is_a?(MissingTranslation) raise exception.to_exception @@ -881,7 +881,7 @@ module I18n end end -I18n.exception_handler = I18n::JustRaiseHandler.new +I18n.exception_handler = I18n::JustRaiseExceptionHandler.new This would re-raise only the +MissingTranslationData+ exception, passing all other input to the default exception handler. -- cgit v1.2.3 From 871cc8c429fb1ae88d8a3e8f75d52367f0a8c50a Mon Sep 17 00:00:00 2001 From: Anil Wadghule Date: Fri, 6 Apr 2012 14:50:45 +0530 Subject: Fix 'Everyday Git' link --- guides/source/contributing_to_ruby_on_rails.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/contributing_to_ruby_on_rails.textile b/guides/source/contributing_to_ruby_on_rails.textile index d0dbb1555a..fbb3483dae 100644 --- a/guides/source/contributing_to_ruby_on_rails.textile +++ b/guides/source/contributing_to_ruby_on_rails.textile @@ -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. -- cgit v1.2.3 From e0672a8e3b900190bac59645465accbab7e08f52 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 7 Apr 2012 16:47:28 +0530 Subject: copy editing [ci skip] --- guides/source/migrations.textile | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'guides/source') diff --git a/guides/source/migrations.textile b/guides/source/migrations.textile index a565974227..0405f45fa8 100644 --- a/guides/source/migrations.textile +++ b/guides/source/migrations.textile @@ -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 explicitly write 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 @@ -636,9 +636,8 @@ $ rake db:migrate:up VERSION=20080906120000 will run the +up+ method from the 20080906120000 migration. This task will first -check whether the migration is already performed, so for example - +db:migrate:up VERSION=20080906120000+ will do nothing if Active Record believes - that 20080906120000 has already been run. +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 -- cgit v1.2.3 From 5916403991e0f3f8f14523827745bae42e2817d1 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 7 Apr 2012 16:47:32 +0530 Subject: Revert "Where migration can get wrong help added" This reverts commit b11113f924d2eb2acbe836954d17a02163f45275. --- guides/source/migrations.textile | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'guides/source') diff --git a/guides/source/migrations.textile b/guides/source/migrations.textile index 0405f45fa8..f663496854 100644 --- a/guides/source/migrations.textile +++ b/guides/source/migrations.textile @@ -927,13 +927,3 @@ features, the +execute+ method can be used to execute arbitrary SQL. You could also use some plugin like "foreigner":https://github.com/matthuhiggins/foreigner which add foreign key support to Active Record (including support for dumping foreign keys in +db/schema.rb+). - -h3. Where you may get into trouble ? - -While running specific migrations with VERSION specified, By mistake if you misspell -command you may get into big trouble. - -Consider scenario where you want to run down migration +db:migrate:down VERSION=324213490000+ -By mistake if you type something like +db:migrate :down VERSION=324213490000+ then it will -change the complete meaning of migration command and it will be migrated like you are -executing +db:migrate VERSION=32421349000+ -- cgit v1.2.3 From ef493c9259d62a761257de7ffd04258811a9f233 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sat, 7 Apr 2012 11:23:47 -0500 Subject: Don't use arel_table in published_and_commented example in querying guide --- guides/source/active_record_querying.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/active_record_querying.textile b/guides/source/active_record_querying.textile index c5755c8308..de55401c1f 100644 --- a/guides/source/active_record_querying.textile +++ b/guides/source/active_record_querying.textile @@ -1004,7 +1004,7 @@ Scopes are also chainable within scopes: 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 -- cgit v1.2.3