draper - visnupriya - spritexchange

7
Draper Decorators/View-Models for Rails Applications Visnupriya. J .R 7 th April 2014 @visnupriya90| github.com/visnupriya © Spritle Software Private Limited | http://www.spritle.com

Upload: spritle-software-private-limit-ed

Post on 17-May-2015

244 views

Category:

Technology


1 download

DESCRIPTION

Draper, decorator, view decorators, Rails 3, Rails 4,

TRANSCRIPT

Page 1: Draper - Visnupriya - spriteXchange

© Spritle Software Private Limited | http://www.spritle.com

DraperDecorators/View-Models for Rails Applications

Visnupriya. J .R7th April 2014

@visnupriya90| github.com/visnupriya

Page 2: Draper - Visnupriya - spriteXchange

© Spritle Software Private Limited | http://www.spritle.com

What is Draper?

• object-oriented layer of presentation logic to your Rails application.

• The idea of Draper is to provide real ruby class between the template and the model.

• To decorate templates.

Page 3: Draper - Visnupriya - spriteXchange

© Spritle Software Private Limited | http://www.spritle.com

Why use Draper?

• Clean up complex view logic• Provides decorators which

bundles view logic in an object oriented fashion

• Easy to test than helpers• Code readability and easy to

maintain• Code reuse

Page 4: Draper - Visnupriya - spriteXchange

© Spritle Software Private Limited | http://www.spritle.com

What is Decorator Pattern?

• It is a design pattern.• It allows behavior to be added to an

individual object, either statically or dynamically, without affecting the behavior of other objects from the same class

Page 5: Draper - Visnupriya - spriteXchange

© Spritle Software Private Limited | http://www.spritle.com

Let’s see how to use?

• Add Draper to your Gemfile• Generate decorator for a model as shown

below• rails generate decorator Article

Page 6: Draper - Visnupriya - spriteXchange

© Spritle Software Private Limited | http://www.spritle.com

SAMPLE CODETime to wakeup

Page 7: Draper - Visnupriya - spriteXchange

© Spritle Software Private Limited | http://www.spritle.com

Questions?

Thank you