@@ -22,86 +22,96 @@ Just `include` the modules that your Rails models or controllers are concerned w
22
22
23
23
Provides human readable unique strings using each model's ` id ` attribute. Great for short URLs. Usage:
24
24
25
- class Person < ActiveRecord::Base
26
- include EncodedId
27
- end
25
+ ``` ruby
26
+ class Person < ActiveRecord ::Base
27
+ include EncodedId
28
+ end
28
29
29
- paul = Person.create name: "Paul"
30
- paul.id # => 20355
31
- paul.encoded_id # => "xyz"
32
- Person.where_encoded_id("xyz").first.name => "Paul"
30
+ paul = Person .create name: " Paul"
31
+ paul.id # => 20355
32
+ paul.encoded_id # => "xyz"
33
+ Person .where_encoded_id(" xyz" ).first.name => " Paul"
34
+ ```
33
35
34
36
### PasswordAuth
35
37
36
38
Provides basic password setting and authenticating via [ bcrypt] [ bcrypt ] . Including models must have an ` encrypted_password ` attribute.
37
39
38
- class User < ActiveRecord::Base
39
- include PasswordAUth
40
- end
40
+ ``` ruby
41
+ class User < ActiveRecord ::Base
42
+ include PasswordAUth
43
+ end
41
44
42
- user = User.new password: "test1234"
43
- user.authenticate "test1234" # => user object
44
- user.authenticate "test4321" # => false
45
+ user = User .new password: " test1234"
46
+ user.authenticate " test1234" # => user object
47
+ user.authenticate " test4321" # => false
48
+ ```
45
49
46
50
### TokenizedAttributes
47
51
48
52
Provides easy generation of random SHA tokens for a model's attributes.
49
53
50
- class Document < ActiveRecord::Base
51
- include TokenizedAttributes
54
+ ``` ruby
55
+ class Document < ActiveRecord ::Base
56
+ include TokenizedAttributes
52
57
53
- tokenize :slug
54
- end
58
+ tokenize :slug
59
+ end
55
60
56
- d = Document.create
57
- d.slug # db89148af5c734ed8f34cb1402b699d63784591f
58
- d.regenerate_token :slug
59
- d.slug # cfa5946b9cb1abc80c02f050f383f06514fb70da
61
+ d = Document .create
62
+ d.slug # db89148af5c734ed8f34cb1402b699d63784591f
63
+ d.regenerate_token :slug
64
+ d.slug # cfa5946b9cb1abc80c02f050f383f06514fb70da
65
+ ```
60
66
61
67
## Controller Concerns Included
62
68
63
69
### JsonRenderer
64
70
65
71
Adds convenience methods for rendering JSON from controllers
66
72
67
- class ThingsController < ApplicationController
68
- include JsonRenderer
73
+ ``` ruby
74
+ class ThingsController < ApplicationController
75
+ include JsonRenderer
69
76
70
- def index
71
- things = Thing.all
72
- ok things
73
- end
77
+ def index
78
+ things = Thing .all
79
+ ok things
80
+ end
74
81
75
- def create
76
- thing = Thing.create params
77
- created thing
78
- end
82
+ def create
83
+ thing = Thing .create params
84
+ created thing
85
+ end
79
86
80
- def destroy
81
- thing = Thing.find params[:id]
82
- thing.destroy
83
- no_content
84
- end
87
+ def destroy
88
+ thing = Thing .find params[:id ]
89
+ thing.destroy
90
+ no_content
91
+ end
85
92
86
- # ... et cetera
87
- end
93
+ # ... et cetera
94
+ end
95
+ ```
88
96
89
97
## Mailer Concerns Included
90
98
91
99
### ResquedDelivery
92
100
93
101
Makes any ` ActionMailer::Base ` subclass transparently send its mail via Resque.
94
102
95
- class OrderMailer < ActionMailer::Base
96
- include ResquedDelivery
103
+ ``` ruby
104
+ class OrderMailer < ActionMailer ::Base
105
+ include ResquedDelivery
97
106
98
- def confirmation order_id
99
- @order = Order.find order_id
100
- mail to: @order.email
101
- end
102
- end
107
+ def confirmation order_id
108
+ @order = Order .find order_id
109
+ mail to: @order .email
110
+ end
111
+ end
103
112
104
- OrderMailer.confirmation(3).deliver # => queued in Resque
113
+ OrderMailer .confirmation(3 ).deliver # => queued in Resque
114
+ ```
105
115
106
116
Note: this concern is short-circuited in ` dev ` and ` test ` environments so you can confirm email is sent like normal
107
117
0 commit comments