mongoid_slug 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.rdoc +31 -2
  2. data/lib/mongoid_slug.rb +2 -2
  3. metadata +7 -7
data/README.rdoc CHANGED
@@ -1,6 +1,12 @@
1
1
  = Mongoid Slug
2
2
 
3
- This gem generates a URL slug/permalink based on a field or set of fields in a Mongoid model.
3
+ == Summary
4
+
5
+ This module, when included in a Mongoid model, generates a URL slug or permalink based on a field or set of fields.
6
+
7
+ == Examples
8
+
9
+ Here we have a book model that embeds many authors:
4
10
 
5
11
  class Book
6
12
  include Mongoid::Document
@@ -19,6 +25,29 @@ This gem generates a URL slug/permalink based on a field or set of fields in a M
19
25
  embedded_in :book, :inverse_of => :authors
20
26
  end
21
27
 
28
+ The finders in our controllers would possibly look like:
29
+
30
+ class BooksController
31
+ def show
32
+ @book = Book.where(:slug => params[:id]).first
33
+ end
34
+
35
+ # and so on
36
+ end
37
+
38
+ class AuthorsController
39
+ def show
40
+ @book = Book.where(:slug => params[:book_id]).first
41
+ @author = @book.authors.where(:slug => params[:id]).first
42
+ end
43
+
44
+ # and so on
45
+ end
46
+
47
+ If you are wondering why I did not include a *find_by_slug* helper, {read on}[http://groups.google.com/group/mongoid/browse_thread/thread/5905589e108d7cc0?pli=1].
48
+
49
+ To demo some more functionality in the console:
50
+
22
51
  >> book = Book.create(:title => "A Thousand Plateaus")
23
52
  >> book.to_param
24
53
  "a-thousand-plateaus"
@@ -36,4 +65,4 @@ This gem generates a URL slug/permalink based on a field or set of fields in a M
36
65
  >> book.authors.where(:slug => 'felix-guattari).first
37
66
  => #<Author _id: 4c31e362faa4a7050e000003, slug: "félix-guattari", last_name: "Guattari", first_name: "Félix">
38
67
 
39
- Check out the sample models in the spec folder for more examples.
68
+ Last but not least, check out the specs and the sample models I used there for more examples.
data/lib/mongoid_slug.rb CHANGED
@@ -36,7 +36,7 @@ module Mongoid::Slug
36
36
 
37
37
  stack.each do |name|
38
38
  if found.any?
39
- found = found.first.send(name)
39
+ found = found.first.send(name).to_a
40
40
  end
41
41
  end
42
42
 
@@ -46,7 +46,7 @@ module Mongoid::Slug
46
46
 
47
47
  def find_unique_slug(suffix='')
48
48
  slug = ("#{slug_base} #{suffix}").parameterize
49
- if find_(slug).to_a.reject{ |doc| doc.id == self.id }.empty?
49
+ if find_(slug).reject{ |doc| doc.id == self.id }.empty?
50
50
  slug
51
51
  else
52
52
  suffix = suffix.blank? ? '1' : "#{suffix.to_i + 1}"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_slug
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 4
10
- version: 0.4.4
9
+ - 5
10
+ version: 0.4.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Hakan Ensari
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-07-08 00:00:00 +01:00
19
+ date: 2010-07-24 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -27,13 +27,13 @@ dependencies:
27
27
  requirements:
28
28
  - - ~>
29
29
  - !ruby/object:Gem::Version
30
- hash: -1848230043
30
+ hash: 31098209
31
31
  segments:
32
32
  - 2
33
33
  - 0
34
34
  - 0
35
- - beta9
36
- version: 2.0.0.beta9
35
+ - beta
36
+ version: 2.0.0.beta
37
37
  type: :runtime
38
38
  version_requirements: *id001
39
39
  description: Mongoid Slug generates a URL slug/permalink based on fields in a Mongoid model.