copass + ruby on rails =

18
Ruby on Rails From simplicity to complexity 07/03/2014 - Presentation for le Wagon

Upload: augustin-riedinger

Post on 05-Jul-2015

539 views

Category:

Technology


0 download

DESCRIPTION

Presentation made at le Wagon (http://www.lewagon.org) to give tips and learnings from the experience of building Copass (http://copass.org) with Ruby on Rails. Interesting gems, dangerous ones, tips and readings, to get started with good practices on Rails at 3 steps of a project: - Bootstrapping - Going on production - Scaling

TRANSCRIPT

Page 1: Copass + Ruby on Rails =

Ruby on RailsFrom simplicity to complexity

07/03/2014 - Presentation for le Wagon

Page 2: Copass + Ruby on Rails =

Ruby on Rails From simplicity to complexity

Going to productionScaling

Bootstrapping

If we were to start over with Copass, what are the good choices we’d keep and the lessons we’d learn?

Page 3: Copass + Ruby on Rails =

Bootstrapping

Page 4: Copass + Ruby on Rails =

Bootstrapping

★ Database: PostgreSQL

★ Front-End: Bootstrap, jQuery

★ Precompiled languages: Haml,

Coffeescript, SASS, Markdown

★ Debugging: Better Errors

★ Authentication: Devise

★ Version Control: Git, Github (of course)

★ Support: Stackoverflow (of course)

★ REST structure

★ MVC structure

★ Ruby tricks

★ Don’t use DB-related gems

★ Multi-steps signup

★ Avoid front-end gems

★ Name things

LESSONS LEARNEDGOOD CHOICES

Page 5: Copass + Ruby on Rails =

Markdown http://en.wikipedia.org/wiki/Markdown

❖ Markdown allows you to write using an easy-to-read, easy-to-write

plain text format, then convert it to structurally valid XHTML (or HTML).

❖ Allows to separate

content from logic !

Anyone can edit

markdown documents

❖ Used by Github,

Stackoverflow etc.

Markdown 3 steps

Page 6: Copass + Ruby on Rails =

Better Errors gem https://github.com/charliesome/better_errors

❖ Best tool for debugging

❖ Displays a live console in your browser

❖ Allows you to:

+ see the content of variables

+ see the source code where

the bug occured

+ includes gem related code

Better error interface

Page 7: Copass + Ruby on Rails =

REST Structure http://en.wikipedia.org/wiki/Representational_state_transfer

❖ Heard of those GET, POST, PUT, DELETE http methods?

❖ Respect the basics:➢ GET : fetches one/many objects, doesn’t change any value (read only)

➢ POST : creates an object

➢ PUT : edit an object

➢ DELETE : delete an object

❖ Advantages:➢ Use the convention among the team

➢ Keeps you router clean

➢ Prevents pages refresh from doing several tie the same action

➢ Good API design

Page 8: Copass + Ruby on Rails =

Don’t use DB related gem❖ We all use many gems to bootstrap faster

❖ Don’t use them when they are database related

❖ Eg. Friendships managed with Amistad

➢ Cool, I have a whole set of methods ready (add friend, remove friend, get

friends, get pending requests etc.)

➢ But I need to add a notification level on each friend

➢ And also some friend suggestions

➢ Errr…. you can’t because it is a gem

➢ Hence double data size, harder management etc.

If you really want this gem, you can either copy paste its code into your project,

or fork it straight away and customize it as you need as if it were your proper code!

Page 9: Copass + Ruby on Rails =

Going to production

Page 10: Copass + Ruby on Rails =

LESSONS LEARNED

Going to production

★ Hosting: Heroku + S3

★ Backups: PGBackups Archive

★ Deployment: Deploy Hooks

★ Spam prevention: Negative

Captcha

★ Maintenance: Exception

Notification, Dead Man Snitch

★ Use Paperclip as a service

★ Testing becomes necessary at

this step

GOOD CHOICES

Page 11: Copass + Ruby on Rails =

Negative Captcha https://github.com/subwindow/negative-captcha

❖ In production, every public form is subject to spam

❖ But Captchas are boring, time consuming, as a user, you’d feel

frustrated, untrusted

❖ Someone invented negative captcha:

❖ Add a fake field that will be filled by robots

but not humans

❖ User experience is the same !

Name

Email

Form

Hidden fieldOk

Filled by Robots not humans

Page 12: Copass + Ruby on Rails =

Scaling

Page 13: Copass + Ruby on Rails =

LESSONS LEARNED

Scaling

★ Web server: Phusion Passenger

★ CDN: Cloudfront

★ Background jobs: Delayed Job +

Workless

★ Database Indexes

★ Memory usage

★ To test: Dynosaur

GOOD CHOICES

Page 14: Copass + Ruby on Rails =

Workless https://github.com/lostboy/workless

❖ Based on delayed jobs : sends tasks to the background by adding .

delay

➢ Eg.

❖ But for background jobs, you need a Heroku worker which costs

money

❖ The awesomeness of workless is that the worker is automatically

scaled up when there are tasks in the queue, and down when it is over

➢ No extra fees!

def generate_sizes_async(erase= false) self.delay.generate_sizes(erase)end

Page 15: Copass + Ruby on Rails =

Next steps

❖ More front end logic➢ Angular

❖ Going Mobile, how?

➢ Ruby Motion ( ), Responsive web design, native app with strong

API

Going mobile

Page 16: Copass + Ruby on Rails =

Tips and reads❖ Subscribe to RubyWeekly newsletter

❖ Very good articles:➔ How to get More Bang for your Heroku Buck While Making Your Rails Site Super Snappy

➔ An Introduction To DOM Events

➔ A basic guide to when and how to deploy HTTPS

➔ What every web developer must know about URL encoding

➔ Ruby Styleguide

➔ Github flow

Page 18: Copass + Ruby on Rails =

http://copass.org