Skip to content

Commit a62978c

Browse files
committed
snaz up code samples in readme
1 parent 2136c4f commit a62978c

File tree

1 file changed

+56
-46
lines changed

1 file changed

+56
-46
lines changed

README.md

Lines changed: 56 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -22,86 +22,96 @@ Just `include` the modules that your Rails models or controllers are concerned w
2222

2323
Provides human readable unique strings using each model's `id` attribute. Great for short URLs. Usage:
2424

25-
class Person < ActiveRecord::Base
26-
include EncodedId
27-
end
25+
```ruby
26+
class Person < ActiveRecord::Base
27+
include EncodedId
28+
end
2829

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+
```
3335

3436
### PasswordAuth
3537

3638
Provides basic password setting and authenticating via [bcrypt][bcrypt]. Including models must have an `encrypted_password` attribute.
3739

38-
class User < ActiveRecord::Base
39-
include PasswordAUth
40-
end
40+
```ruby
41+
class User < ActiveRecord::Base
42+
include PasswordAUth
43+
end
4144

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+
```
4549

4650
### TokenizedAttributes
4751

4852
Provides easy generation of random SHA tokens for a model's attributes.
4953

50-
class Document < ActiveRecord::Base
51-
include TokenizedAttributes
54+
```ruby
55+
class Document < ActiveRecord::Base
56+
include TokenizedAttributes
5257

53-
tokenize :slug
54-
end
58+
tokenize :slug
59+
end
5560

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+
```
6066

6167
## Controller Concerns Included
6268

6369
### JsonRenderer
6470

6571
Adds convenience methods for rendering JSON from controllers
6672

67-
class ThingsController < ApplicationController
68-
include JsonRenderer
73+
```ruby
74+
class ThingsController < ApplicationController
75+
include JsonRenderer
6976

70-
def index
71-
things = Thing.all
72-
ok things
73-
end
77+
def index
78+
things = Thing.all
79+
ok things
80+
end
7481

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
7986

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
8592

86-
# ... et cetera
87-
end
93+
# ... et cetera
94+
end
95+
```
8896

8997
## Mailer Concerns Included
9098

9199
### ResquedDelivery
92100

93101
Makes any `ActionMailer::Base` subclass transparently send its mail via Resque.
94102

95-
class OrderMailer < ActionMailer::Base
96-
include ResquedDelivery
103+
```ruby
104+
class OrderMailer < ActionMailer::Base
105+
include ResquedDelivery
97106

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
103112

104-
OrderMailer.confirmation(3).deliver # => queued in Resque
113+
OrderMailer.confirmation(3).deliver # => queued in Resque
114+
```
105115

106116
Note: this concern is short-circuited in `dev` and `test` environments so you can confirm email is sent like normal
107117

0 commit comments

Comments
 (0)