Powerful Google developer tools for immediate impact! (2023-24 C)
Angular.js + Rails at WeWork or: The Accidental Feature
1. Angular.js + Rails = ♥
or: The Accidental Feature
By Jonathan E. Magen / @yonkeltron Sr. Software Engineer, WeWork
2. Identify yourself
Jonathan E. Magen / yonkeltron errywhere else
Practitioner of the Computer Sciences
Research @ The Evergreen State College Advanced OS Lab
WeWork engineer
3. About WeWork
“ We want to change the way people work. ”
- Adam Neumann, WeWork Co-Founder
“ Design to make people happy. ”
- Miguel McKelvey, WeWork Co-Founder
7 Buildings
3 Cities
4000+ Members
Services for the community
8. Things we've built with
Angular
Audit trail + changelog inspector using audited gem
Infinite scroll using will_paginate gem
Inline edit
Lots of stuff using ngResource
10. Free RESTful JSON endpoints
casOfrnsotolr<Apiainotolr
ls feigCnrle plctoCnrle
dfidx
e ne
@feig =Ofrn.aeprm[pg]
ofrns feigpg(aas:ae)
rsodt d |omt
epn_o o fra|
fra.tl#idxhm.r
omthm ne.tleb
fra.sn{rne jo:@feig,ro:fle}
omtjo edr sn ofrns ot as
ed
n
ed
n
#ohratos.
te cin..
ed
n
ActiveRecord → JSON → HTTP
12. Rails renders Angular template HTML
Times you might want to do this:
Permissions: only rendering parts of a template
Dynamically populate form s l c options
eet
Internationalization!
13. Permission-driven rendering
<=i cretue.a_oe :uio %
% f urn_srhsrl? adtr >
<i dt-gap"pcmn>
dv aan-p=saea"
<i dt-uis"e"
dv aaadt=yp
dt-uial-ye"% Ofrn.os%"
aaadtbetp=<= feigt_ >
dt-uial-d"% @feigi %"<dv
aaadtbei=<= ofrn.d >>/i>
<dv
/i>
< ed%
% n >
Only render the audit inspector directive iff the current user has the
authorization to access audit data
14. i18n API column headers
<al cas"al tbesrpd dt-gap"pcmn>
tbe ls=tbe al-tie" aan-p=saea"
<ha>
ted
<h<=Ofrn.ua_trbt_ae:ae %<t>
t>% feighmnatiuenm(nm) >/h
<h<=Ofrn.ua_trbt_ae:aeoiain %<t>
t>% feighmnatiuenm(ctgrzto) >/h
<h<=Ofrn.ua_trbt_ae:rc)%<t>
t>% feighmnatiuenm(pie >/h
<h<t>
t>/h
<h<t>
t>/h
<ted
/ha>
t e drendered by Rails includes localized column headers. This
ha
lets Angular render the t o ycontaining actual data.
bd
20. Yeah, I know there were easier
ways to do this
Gorillions of jQuery plugins
Far fewer Angular-friendly options
Google Groups
StackOverflow
We knew we'd need Angular.js but
wanted to ease our way in gradually
21. A subtle rejection of ngGrid
Reimplementing t b ein terms of d v
al i
Does way more than what we needed
Sub project of Angular UI
TBH: Angular.js could really use widgets
Web Components?
23. Offerings controller
saea.otolr'feig' fnto (soe sacPrmevc,Ofrn){
pcmncnrle(ofrns, ucin $cp, erhaaSrie feig
cnoelg'feig Cnolr)
osl.o(Ofrns otle';
$cp.feig =Ofrn.ur(;/ nRsuc ZM!
soeofrns feigqey) / geore OG
$cp.dtnTgl =fnto eiigogeofrn){
soeeiigoge ucin dtnTgl(feig
i (feigeiig {
f ofrn.dtn)
Ofrn.paeofrn)
feigudt(feig;
ofrn.dtn =fle
feigeiig as;
}es {
le
ofrn.dtn =tu;
feigeiig re
}
};
};
)
24. The show/hide model for cells
in the table body
<bd dt-gcnrle=ofrns>
toy aan-otolr"feig"
<rdt-grpa=ofrn i ofrns>
t aan-eet"feig n feig"
<d
t>
< he=/feig/{feigi}"
a rf"ofrns{ofrn.d}
dt-gso=!feigeiig>{feignm}<a
aan-hw"ofrn.dtn"{ofrn.ae}/>
<nu dt-gso=ofrn.dtn"
ipt aan-hw"feigeiig
tp=tx"dt-gmdl"feignm"rqie/
ye"et aan-oe=ofrn.ae eurd>
<t>
/d
show(value) ⊕ show(input)