Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rails Presenters

Rails Presenters

Revath S Kumar

August 07, 2014
Tweet

More Decks by Revath S Kumar

Other Decks in Programming

Transcript

  1. ABOUT Rubyist / JavaScripter Yeoman Team Member @keralarb / @keralajs

    Works at @whatznear Blog at blog.revathskumar.com Twitter/Github - @revathskumar +RevathSKumar
  2. WHAT ABOUT CONDITIONS? LIKE < % i f @ u

    s e r . w e b s i t e . p r e s e n t ? % > < % = l i n k _ t o @ u s e r . w e b s i t e , @ u s e r . w e b s i t e % > < % e l s e % > < s p a n c l a s s = " n o n e " > N o n e g i v e n < / s p a n > < % e n d % > WE USUALLY DO, RIGHT?
  3. BUT RAILS HELPERS ARE PROCEDURAL < % = w e

    b p a g e ( @ u s e r . w e b s i t e ) % >
  4. IT WILL BE BETTER IF IT CAN BE USED AS

    < % = @ u s e r . w e b p a g e % > Shorter, Simpler and sleek
  5. # a p p / p r e s e

    n t e r s / u s e r _ p r e s e n t e r . r b c l a s s U s e r P r e s e n t e r d e f i n i t i a l i z e u s e r , t e m p l a t e @ u s e r = u s e r @ t e m p l a t e = t e m p l a t e e n d d e f w e b s i t e i f @ u s e r . w e b s i t e . p r e s e n t ? @ t e m p l a t e . l i n k _ t o @ u s e r . w e b s i t e , @ u s e r . w e b s i t e e l s e @ t e m p l a t e . c o n t e n t _ t a g : s p a n , ' N o n e G i v e n ' , c l a s s : ' n o n e ' e n d e n d e n d -- # a p p / c o n t r o l l e r s / u s e r _ c o n t r o l l e r . r b c l a s s U s e r C o n t r o l l e r < A p p l i c a t i o n C o n t r o l l e r d e f s h o w u s e r = U s e r . f i n d ( p a r a m s [ : i d ] ) @ u s e r = U s e r P r e s e n t e r . n e w ( u s e r , v i e w _ c o n t e x t ) e n d e n d
  6. IN VIEW AFTER USING 'PRESENTER' < ! - - a

    p p / v i e w s / u s e r s / s h o w . h t m l . e r b - - > < d t > W e b s i t e : < / d t > < d d > < % = @ u s e r . w e b s i t e % > < / d d >