Skip to content

Commit

Permalink
Update example in the Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
dejan committed Oct 14, 2016
1 parent 2f5cf91 commit 17f7aa6
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions README.md
Expand Up @@ -65,15 +65,15 @@ Bellow is the list of bundled filters along with their optional arguments on ini

## Using AutoHtml with ActiveRecord

For performance reasons it's a good idea to store the formated output in the database in a separate column so that it's not generated every time.
For performance reasons it's a good idea to store the formated output in the database, in a separate column, to avoid generating the same content on each access.
This can be acomplished simply by overriding the attribute writter:

```ruby
class Comment < ActiveRecord::Base

FORMAT = AutoHtml::Pipeline.new(
AutoHtml::HtmlEscape.new,
AutoHtml::Link.new(target: '_blank'))
AutoHtml::Markdown.new
)

def text=(t)
super(t)
Expand All @@ -82,6 +82,13 @@ class Comment < ActiveRecord::Base
end
```

Now, every time `text` attribute is set, `text_html` will be set as well:

```Ruby
comment = Comment.new(text: 'Hey!')
comment.text_html # => '<p>Hey!</p>'
```

## Code status

[![Circle CI](https://circleci.com/gh/dejan/auto_html.svg?style=svg&circle-token=57823c8b62302106564f97b58b64643b9760ed99)](https://circleci.com/gh/dejan/auto_html)
Expand Down

0 comments on commit 17f7aa6

Please sign in to comment.