Added install generator to the README
This commit is contained in:
parent
f3f32233cd
commit
2e1f5160a7
|
@ -6,19 +6,20 @@
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
1. Add `gem 'draper'` to your `Gemfile` and `bundle`
|
1. Add `gem 'draper'` to your `Gemfile` and `bundle`
|
||||||
2. Run `rails g draper:decorator YourModel`
|
2. Run `rails g draper:install` to create the directory and `ApplicationDecorator`
|
||||||
3. Edit `app/decorators/[your_model]_decorator.rb` using:
|
3. Run `rails g draper:decorator YourModel`
|
||||||
|
4. Edit `app/decorators/[your_model]_decorator.rb` using:
|
||||||
1. `h` to proxy to Rails/application helpers like `h.current_user`
|
1. `h` to proxy to Rails/application helpers like `h.current_user`
|
||||||
2. `[your_model]` to access the wrapped object like `article.created_at`
|
2. `[your_model]` to access the wrapped object like `article.created_at`
|
||||||
4. Put common decorations in `app/decorators/application.rb`
|
5. Put common decorations in `app/decorators/application.rb`
|
||||||
5. Wrap models in your controller with the decorator using:
|
6. Wrap models in your controller with the decorator using:
|
||||||
1. `.find` automatic lookup & wrap
|
1. `.find` automatic lookup & wrap
|
||||||
ex: `ArticleDecorator.find(1)`
|
ex: `ArticleDecorator.find(1)`
|
||||||
2. `.decorate` method with single object or collection,
|
2. `.decorate` method with single object or collection,
|
||||||
ex: `ArticleDecorator.decorate(Article.all)`
|
ex: `ArticleDecorator.decorate(Article.all)`
|
||||||
3. `.new` method with single object
|
3. `.new` method with single object
|
||||||
ex: `ArticleDecorator.new(Article.first)`
|
ex: `ArticleDecorator.new(Article.first)`
|
||||||
6. Output the instance methods in your view templates
|
7. Output the instance methods in your view templates
|
||||||
ex: `@article_decorator.created_at`
|
ex: `@article_decorator.created_at`
|
||||||
|
|
||||||
## Watch the RailsCast
|
## Watch the RailsCast
|
||||||
|
|
Loading…
Reference in New Issue