Permalink
Browse files

Update example in the Readme

  • Loading branch information...
1 parent 2f5cf91 commit 17f7aa6ab8c7d22cc46a3228aa5f31dc7cdb745f @dejan committed Oct 14, 2016
Showing with 10 additions and 3 deletions.
  1. +10 −3 README.md
View
@@ -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)
@@ -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)

0 comments on commit 17f7aa6

Please sign in to comment.