$30 off During Our Annual Pro Sale. View Details »

Getting Started with Ruby on Rails

Vero Rebagliatte
June 12, 2013
130

Getting Started with Ruby on Rails

Vero Rebagliatte

June 12, 2013
Tweet

Transcript

  1. GETTING STARTED WITH
    RUBY ON RAILS

    View Slide

  2. @rebagliatte
    Vero Rebagliatte

    View Slide

  3. Forecast
    1. What’s ROR?
    2. The rails way
    3. Example app

    View Slide

  4. What’s ROR?

    View Slide

  5. It’s a framework

    View Slide

  6. Was created by DHH

    View Slide

  7. Lowers the barrier to start programming in Ruby

    View Slide

  8. Opinionated

    View Slide

  9. The Rails Way

    View Slide

  10. Be DRY, don’t repeat yourself

    View Slide

  11. Prefer convention over configuration

    View Slide

  12. Be RESTful

    View Slide

  13. REST uses operations of the HTTP protocol

    View Slide

  14. REST
    GET
    PUT
    POST
    PATCH
    DELETE
    SOAP
    getUsers()
    getNewUsersSince()
    savePurchaseOrder()
    getUser()
    addUser()
    removeUser()
    updateUser()
    getLocation()

    View Slide

  15. REST uses resources

    View Slide

  16. http://myblog.com/posts/
    GET
    PUT
    POST
    DELETE
    http://myblog.com/posts/1
    GET
    PUT
    POST
    DELETE
    }
    }

    View Slide

  17. Blog::Application.routes.draw do
    resources :posts
    end
    config/routes.rb

    View Slide

  18. Use the MVC (Model View Controller) Pattern

    View Slide

  19. View Slide

  20. class Post < ActiveRecord::Base
    attr_accessible :content, :name, :title
    has_many :commenters
    validates :title, presence: true
    end
    app/models/post.rb

    View Slide

  21. Post <%= @post.title %>
    <%= @post.content %>
    <%= link_to 'Edit', edit_post_path(@post) %>
    <%= link_to 'Back', posts_path %>
    app/views/posts/show.rb

    View Slide

  22. class PostsController < ApplicationController
    def new
    @post = Post.new
    end
    def create
    @post = Post.new(params[:post])
    if @post.save
    redirect_to @post, notice: 'Post created!'
    else
    render action: :new
    end
    end
    end app/controllers/posts_controller.rb

    View Slide

  23. View Slide

  24. Package your code for reuse

    View Slide

  25. source 'https://rubygems.org'
    gem 'rails', '3.2.13'
    gem 'sqlite3'
    group :assets do
    gem 'sass-rails', '~> 3.2.3'
    gem 'coffee-rails', '~> 3.2.1'
    gem 'uglifier', '>= 1.0.3'
    end
    gem 'jquery-rails'
    Gemfile

    View Slide

  26. Be fast by default with the Asset Pipeline

    View Slide

  27. View Slide

  28. app/assets
    assets from the current application
    lib/assets
    your own libraries, shared across applications
    vendor/assets
    third party assets(js plugins, css frameworks)

    View Slide

  29. PRECOMPILE

    View Slide

  30. View Slide

  31. CONCATENATE

    View Slide

  32. View Slide

  33. application.css application.js logo.jpg
    application-908e25f4bf641
    868d8683022a5b62f54.css
    application-908e25f4bf641
    868d8683022a5b62f54.js
    logo-908e25f4bf641868d8
    683022a5b62f54.jpg
    ADD MD5 FINGERPRINT

    View Slide

  34. COMPRESS

    View Slide

  35. More

    View Slide

  36. Internationalize your app

    View Slide

  37. Use generators

    View Slide

  38. Example App

    View Slide

  39. View Slide

  40. Thanks!
    @rebagliatte

    View Slide