Browse files

Merge branch 'master' of

  • Loading branch information...
norman committed Apr 28, 2012
2 parents 22925a6 + 50499f0 commit 233b6f582b2f4a500e96c422483d9d5265b277a4
Showing with 12 additions and 4 deletions.
  1. +6 −2 Guide.rdoc
  2. +3 −1 lib/friendly_id/globalize.rb
  3. +3 −1 test/globalize_test.rb
@@ -114,8 +114,9 @@ store them in a field in your model. By default, this field must be named
+:slug+, though you may change this using the
{FriendlyId::Slugged::Configuration#slug_column slug_column} configuration
option. You should add an index to this column, and in most cases, make it
-unique. You may also wish to constrain it to NOT NULL, but this depends on your
-app's behavior and requirements.
+unique. Do not make the column unique in case you wish to scope the slug
+(more on this later). You may also wish to constrain it to NOT NULL, but this
+depends on your app's behavior and requirements.
=== Example Setup
@@ -356,6 +357,9 @@ Without :scoped in this case, one of the restaurants would have the slug
The value for the +:scope+ option can be the name of a +belongs_to+ relation, or
a column.
+Please do note that you must drop the uniqueness constraint on the slug's
+column in the database when you're scoping the slug.
=== Finding Records by Friendly ID
If you are using scopes your friendly ids may not be unique, so a simple find
@@ -87,10 +87,12 @@ def find_one(id)
found = includes(:translations).
where(translation_class.arel_table[:locale].in([I18n.locale, I18n.default_locale])).
where(translation_class.arel_table[@klass.friendly_id_config.query_field].eq(id)).first if found.nil?
- # if locale is not translated fallback to default locale
if found
+ # Reload the translations for the found records.
found.tap { |f| f.translations.reload }
+ # if locale is not translated fallback to default locale
@@ -32,7 +32,9 @@ class GlobalizeTest < MiniTest::Unit::TestCase
article = TranslatedArticle.create(:title => 'a title')
Globalize.with_locale(:ja) { article.update_attributes(:title => 'タイトル') }
article_by_friendly_id = TranslatedArticle.find("a-title")
- assert_equal article.translations, article_by_friendly_id.translations
+ article.translations.each do |translation|
+ assert_includes article_by_friendly_id.translations, translation
+ end

0 comments on commit 233b6f5

Please sign in to comment.