好的命名才好找 • Copy & Paste is Good 剪剪貼貼萬能 • No Thinking, Speci fi c First 別想太多,先當特殊設計 • Encounter Twice +, Refactor as Shared ⽤習慣了,才做成共⽤設計 • Cut Layout into Sections 學習剪紙的藝術 • Group Sections to Folders 保持整⿑很重要 • Less than 3 Layers of Folders 不要疊超過三層
respond_with / respond_to / redirect_to • send_data / send_ fi le / render( fi le: fi le) • show.html.erb / show.json.jbuilder • View variants • show.html+mobile.erb • render :show, variants: [:mobile, :desktop] • request.variant = :redesign request.variant = :theme • Use as status: success & failure • Use as data source • View helpers • Pre fi x with namespace • No instance variables • Controller helpers • De fi ne requirements in fi rst stage • Controller modules • Group helpers in fi rst stage • Group logics in second stage
rendered HTML • Work with Turbo: MutationObserver API • Javascript worked in scoped DOM • <div data-controller=“clipboard”>…</div> • Auto initialized via connect() • Focus on behaviors of controller • Data Attributes • data-controller : this.element • data-xxx-target : this.xxxTarget • data-xxx-value : this.xxxValue • data-action • <button data-action=“clipboard#copy”> Copy to Clipboard</button>
• Use concern • Use mount (Engine) • Split routes to fi les • con fi g.paths[‘con fi g/routes.rb’].concat (Dir[Rails.root.join(‘con fi g/routes/*.rb’)].sort) • Well designed controllers & actions • Controller helpers • De fi ne requirements in fi rst stage • Refactor into methods & associations of model • Controller modules • Group helpers in fi rst stage • Group logics in second stage • Rewrite into Services