friendly_id 3.1.7 → 3.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +4 -0
- data/Guide.md +8 -1
- data/Rakefile +0 -1
- data/lib/friendly_id/active_record_adapter/relation.rb +8 -3
- data/lib/friendly_id/version.rb +1 -1
- metadata +47 -7
data/Changelog.md
CHANGED
data/Guide.md
CHANGED
@@ -447,7 +447,6 @@ the slug "joes-diner" if it's located in a different city:
|
|
447
447
|
|
448
448
|
Restaurant.find("joes-diner", :scope => "seattle") # returns 1 record
|
449
449
|
Restaurant.find("joes-diner", :scope => "chicago") # returns 1 record
|
450
|
-
Restaurant.find(:all, "joes-diner") # returns both records
|
451
450
|
|
452
451
|
The value for the `:scope` key in your model can be a custom method you
|
453
452
|
define, or the name of a relation. If it's the name of a relation, then the
|
@@ -455,6 +454,14 @@ scope's text value will be the result of calling `to_param` on the related
|
|
455
454
|
model record. In the example above, the city model also uses FriendlyId and so
|
456
455
|
its `to_param` method returns its friendly_id: "chicago" or "seattle".
|
457
456
|
|
457
|
+
If you want to find all records with a partular friendly\_id regardless of scope,
|
458
|
+
this is a slightly more complicated, but doable:
|
459
|
+
|
460
|
+
name, sequence = params[:id].parse_friendly_id
|
461
|
+
Restaurant.find(:all, :joins => :slugs, :conditions => {
|
462
|
+
:slugs => {:name => name, :sequence => sequence}
|
463
|
+
})
|
464
|
+
|
458
465
|
### Updating a Relation's Scoped Slugs
|
459
466
|
|
460
467
|
When using a relation as the scope, updating the relation will update the
|
data/Rakefile
CHANGED
@@ -84,7 +84,7 @@ module FriendlyId
|
|
84
84
|
return find_some_using_slug(friendly_ids, unfriendly_ids) if use_slugs_table
|
85
85
|
column = fc.cache_column || fc.column
|
86
86
|
friendly = arel_table[column].in(friendly_ids)
|
87
|
-
unfriendly = arel_table[relation.primary_key].in unfriendly_ids
|
87
|
+
unfriendly = arel_table[relation.primary_key.name].in unfriendly_ids
|
88
88
|
if friendly_ids.present? && unfriendly_ids.present?
|
89
89
|
where(friendly.or(unfriendly))
|
90
90
|
else
|
@@ -94,7 +94,7 @@ module FriendlyId
|
|
94
94
|
|
95
95
|
def find_some_using_slug(friendly_ids, unfriendly_ids)
|
96
96
|
ids = [unfriendly_ids + sluggable_ids_for(friendly_ids)].flatten.uniq
|
97
|
-
where(arel_table[relation.primary_key].in(ids))
|
97
|
+
where(arel_table[relation.primary_key.name].in(ids))
|
98
98
|
end
|
99
99
|
|
100
100
|
def sluggable_ids_for(ids)
|
@@ -166,7 +166,12 @@ module FriendlyId
|
|
166
166
|
|
167
167
|
def find_some(ids)
|
168
168
|
return super unless klass.uses_friendly_id?
|
169
|
-
Find.new(self, ids).find_some or
|
169
|
+
Find.new(self, ids).find_some or begin
|
170
|
+
# A change in Arel 2.0.x causes find_some to fail with arrays of instances; not sure why.
|
171
|
+
# This is an emergency, temporary fix.
|
172
|
+
ids = ids.map {|id| (id.respond_to?(:friendly_id_config) ? id.id : id).to_i}
|
173
|
+
super
|
174
|
+
end
|
170
175
|
rescue ActiveRecord::RecordNotFound => error
|
171
176
|
find ? find.raise_error(error) : raise(error)
|
172
177
|
end
|
data/lib/friendly_id/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 3
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 3.1.
|
8
|
+
- 8
|
9
|
+
version: 3.1.8
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Norman Clarke
|
@@ -16,11 +16,12 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-
|
19
|
+
date: 2010-11-22 00:00:00 -03:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
23
|
name: babosa
|
24
|
+
prerelease: false
|
24
25
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
26
|
none: false
|
26
27
|
requirements:
|
@@ -32,9 +33,50 @@ dependencies:
|
|
32
33
|
- 0
|
33
34
|
version: 0.2.0
|
34
35
|
type: :runtime
|
35
|
-
prerelease: false
|
36
36
|
version_requirements: *id001
|
37
|
-
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: activerecord
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
segments:
|
46
|
+
- 3
|
47
|
+
- 0
|
48
|
+
- 0
|
49
|
+
version: 3.0.0
|
50
|
+
type: :development
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: mocha
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
- 9
|
63
|
+
version: "0.9"
|
64
|
+
type: :development
|
65
|
+
version_requirements: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: sqlite3-ruby
|
68
|
+
prerelease: false
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
segments:
|
75
|
+
- 1
|
76
|
+
version: "1"
|
77
|
+
type: :development
|
78
|
+
version_requirements: *id004
|
79
|
+
description: " FriendlyId is the \"Swiss Army bulldozer\" of slugging and permalink plugins\n for Ruby on Rails. It allows you to create pretty URL's and work with\n human-friendly strings as if they were numeric ids for ActiveRecord models.\n"
|
38
80
|
email:
|
39
81
|
- norman@njclarke.com
|
40
82
|
- adrian@mugnolo.com
|
@@ -117,7 +159,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
117
159
|
requirements:
|
118
160
|
- - ">="
|
119
161
|
- !ruby/object:Gem::Version
|
120
|
-
hash: -1691512069096853799
|
121
162
|
segments:
|
122
163
|
- 0
|
123
164
|
version: "0"
|
@@ -126,7 +167,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
167
|
requirements:
|
127
168
|
- - ">="
|
128
169
|
- !ruby/object:Gem::Version
|
129
|
-
hash: -1691512069096853799
|
130
170
|
segments:
|
131
171
|
- 0
|
132
172
|
version: "0"
|