draper - visnupriya - spritexchange
DESCRIPTION
Draper, decorator, view decorators, Rails 3, Rails 4,TRANSCRIPT
© Spritle Software Private Limited | http://www.spritle.com
DraperDecorators/View-Models for Rails Applications
Visnupriya. J .R7th April 2014
@visnupriya90| github.com/visnupriya
© 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.
© 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
© 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
© 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
© Spritle Software Private Limited | http://www.spritle.com
SAMPLE CODETime to wakeup
© Spritle Software Private Limited | http://www.spritle.com
Questions?
Thank you