Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:norman/friendly_id

  • Loading branch information...
commit 233b6f582b2f4a500e96c422483d9d5265b277a4 2 parents 22925a6 + 50499f0
@norman authored
View
8 Guide.rdoc
@@ -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
View
4 lib/friendly_id/globalize.rb
@@ -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 }
else
+ # if locale is not translated fallback to default locale
super
end
end
View
4 test/globalize_test.rb
@@ -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
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.