Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby on Rails Introduction

Ruby on Rails Introduction

This is an introduction of Ruby and Ruby on Rails for Alicante Tech Meetup 2015/07/14

Yusuke Mito

July 15, 2015
Tweet

More Decks by Yusuke Mito

Other Decks in Technology

Transcript

  1. Rail
    to
    the Ruby and Rails
    world

    View full-size slide

  2. :VTVLF.JUP
    $PPLQBE*OD
    -JWJOHJO"MJDBOUFTJODF.BZ
    Z !Z@

    View full-size slide

  3. Cookpad
    http://info.mis-recetas.org/jobs/
    Our mission
    Make everyday cooking fun
    We’re searching for No.1 engineer!
    Cookpad is
    A company which solves user’s issues by technology
    A company which solves issues of all the people in the world

    View full-size slide

  4. 1995 v0.95
    History of Ruby
    2003 v1.8
    2007 v1.9
    2013 Feb. v2.0
    2013 Dec. v2.1
    2014 v2.2
    Ruby is intensively developed over 20 years

    View full-size slide

  5. $ cat hello.rb
    class Hello
    def initialize(name)
    @name = name
    end
    def say
    puts "Hello, #{@name}!"
    end
    end
    hello = Hello.new("David")
    hello.say
    $ ruby hello.rb
    #=> Hello, David!
    class declaration→
    method declaration→
    Instantiation→
    Method call→
    Basic Ruby Syntax
    instance variable→

    View full-size slide

  6. 3 Must-Know Tools
    for Ruby developing
    rbenv
    RubyGems
    bundler

    View full-size slide

  7. rbenv
    # install ruby 2.1.5
    $ rbenv install 2.1.5
    $ rbenv shell 2.1.5
    $ ruby -v
    ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]
    # install ruby 2.2.2
    $ rbenv install 2.2.2
    $ rbenv shell 2.2.2
    $ ruby -v
    ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
    Simple Ruby Version Management Tool
    There are similar tools for other languages: plenv phpenv pyenv…

    View full-size slide

  8. RubyGems is a standard package manager for the Ruby
    Anyone can make own gem and publish it to https://rubygems.org
    RubyGems
    # install gem
    $ gem install nokogiri
    $ irb
    > require ‘nokogiri’
    > doc = Nokogiri::HTML.parse('world')
    > doc.search('.hello').text
    => "world"
    * irb is Interactive Ruby. REPL for Ruby.
    Similar to PEAR for PHP, CPAN for Perl, pip for Python, npm for Node.js etc

    View full-size slide

  9. Managing the gems that the application depends on
    Bundler
    $ cat Gemfile
    source ‘https://rubygems.org'
    gem ‘nokogiri’
    gem ‘rails’
    $ bundle
    #=> Install all gems listed in Gemfile
    Bundler makes sure Ruby applications run the same code on every
    machine by installing given list of gems and its depending gems
    Similar to composer for PHP, carton for Perl, CocoaPods for iOS, etc

    View full-size slide

  10. So, Let’s begin to talk about Rails

    View full-size slide

  11. Ruby on Rails

    View full-size slide

  12. Ruby on Rails is
    a web application framework
    based on MVC pattern

    View full-size slide

  13. Rails builds up with
    multiple sub frameworks

    View full-size slide

  14. Model - ActiveRecord - O/R Mapper
    View - ActionView - View Template Handler
    Controller - ActionPack - Request/Response Handler
    Most important frameworks

    View full-size slide

  15. ActiveSupport - Utilities and Ruby Extensions
    ActiveJob - Asynchronous Job Queue
    ActionMailer - Email Delivering
    And other useful frameworks

    View full-size slide

  16. Demo
    Making simple Rails application from scratch

    View full-size slide

  17. Haml is a template language that provides more simple and clean
    syntax for markup
    Haml

    <%= post.title %>
    <%= post.subtitle %>

    <%= post.content %>


    %section.container
    %h1= post.title
    %h2= post.subtitle
    .content
    = post.content

    View full-size slide

  18. You can build a complex form with less code than default form builder
    Simple Form
    <%= form_for @user do |f| %>

    <%= f.label :name %>
    <%= f.text_field :name %>


    <%= f.label :email %>
    <%= f.text_field :email %>


    <%= f.label :birthday %>
    <%= f.date_field :birthday %>


    <%= f.submit %>

    <% end %>
    <%= simple_form_for @user do |f| %>
    <%= f.input :name %>
    <%= f.input :email %>
    <%= f.input :birthday %>
    <%= f.button :submit %>
    <% end %>

    View full-size slide

  19. Use Ruby REPL everywhere
    Web Console

    View full-size slide

  20. carrierwave - Flexible Image Uploader
    kaminari - De facto paginator for Rails
    omniauth - Standardizes multi provider authentication
    redcarpet - Markdown parser and renderer
    Other useful gems

    View full-size slide

  21. Rails Guides - Official guide of rails
    http://guides.rubyonrails.org/
    Rails Girls Guides - Rails guide for beginner programmer
    http://guides.railsgirls.com/
    Rails Tutorial
    https://www.railstutorial.org/book
    Rails API References
    http://api.rubyonrails.org/
    Good documents to learn Rails

    View full-size slide