Learning Ruby/Rails

What is Rails?

  • It is a framework for building web applications
  • Rails is installed as a Ruby gem
  • The framework is composed of other gems
  • It uses the MVC pattern*
  • Built around 'convention over configuration' and DRY concepts

* for some value of...

Important Concepts

  • REST
  • Routing
  • Asset pipeline
  • The ecosystem
  • Don't fight the defaults

Routing explained: http://guides.rubyonrails.org/routing.html

Project Structure

  • app: controllers, models and views (this is where you spend a lot of your time)
  • config: configuration for your routes and app
  • db: database schema and migrations
  • Gemfile & Gemfile.lock: your dependencies. See http://bundler.io
  • lib: a place to store your custom modules specific to your app
  • log: logfiles! named for each environment
  • test: the home of your minitests
  • features: if your app uses cucumber your tests are in here

Some important folders

Rails @ Sky

  • Example project: https://github.com/sky-uk/sky_stack
  • Rails is used in Sky Service for some larger applications, usually with a customer interface. Rarely used for API's.
  • Heroku: to deploy and host
  • New Relic: to monitor and alert

Taking over a Rails project

  • config/routes.rb - Rails is all about the URL's - see what your application actually does
  • db/schema.rb - what does the DB look like?
  • test strategy - are there any tests? do they work?
  • initializers - check the config/intializers folder to see what code your app runs at startup
  • deployment - how does it get deployed?

Look at these files and folders first

Ecosystem

  • 'Classic' Rails vs. Actual Rails: what you see in production Rails apps often differs greatly from tutorials
  • Lots of pre-existing gems: rarely need to build something new: devise, sidekiq etc.
  • Contribute!

https://rubygems.org/

https://www.ruby-toolbox.com/

https://github.com/rails

http://twitter.com/dhh

http://tenderlovemaking.com/

Testing Rails

  • Don't care what you use: just write tests!
  • Test strategy is up to squad
  • gems: minitest, rspec, cucumber
  • helper gems: webmock, ffaker, factory girl
  • tests need to run without external dependencies
  • No fake API servers on the web!

When to use Rails...

  • Not new and shiny anymore - this is a good thing
  • Mature software - solves problems you may not be considering
  • Mature ecosystem
  • Deployment is a solved problem
  • Great for traditional web applications
  • Rails 5 promises better API support

Further info...

  • Book: Agile Web Development with Rails
  • Book: https://www.railstutorial.org/book
  • https://github.com/thoughtbot/guides/tree/master/best-practices#rails
  • https://robots.thoughtbot.com 
  • https://www.ruby-toolbox.com 
  • http://guides.rubyonrails.org 

Learning Rails

By David Thompson

Learning Rails

  • 448