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

80046ac4618076c5369398b92db8f313?s=128

Yusuke Mito

July 15, 2015
Tweet

Transcript

  1. Rail to the Ruby and Rails world

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

  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
  4. Ruby

  5. 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
  6. $ 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→
  7. 3 Must-Know Tools for Ruby developing rbenv RubyGems bundler

  8. 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…
  9. 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('<div class="hello">world</div>') > 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
  10. 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
  11. So, Let’s begin to talk about Rails

  12. Ruby on Rails

  13. Ruby on Rails is a web application framework based on

    MVC pattern
  14. Rails builds up with multiple sub frameworks

  15. Model - ActiveRecord - O/R Mapper View - ActionView -

    View Template Handler Controller - ActionPack - Request/Response Handler Most important frameworks
  16. ActiveSupport - Utilities and Ruby Extensions ActiveJob - Asynchronous Job

    Queue ActionMailer - Email Delivering And other useful frameworks
  17. Demo Making simple Rails application from scratch

  18. Useful Gems

  19. Haml is a template language that provides more simple and

    clean syntax for markup Haml <section class=”container”> <h1><%= post.title %></h1> <h2><%= post.subtitle %></h2> <div class=”content”> <%= post.content %> </div> </section> %section.container %h1= post.title %h2= post.subtitle .content = post.content
  20. You can build a complex form with less code than

    default form builder Simple Form <%= form_for @user do |f| %> <div> <%= f.label :name %> <%= f.text_field :name %> </div> <div> <%= f.label :email %> <%= f.text_field :email %> </div> <div> <%= f.label :birthday %> <%= f.date_field :birthday %> </div> <div> <%= f.submit %> </div> <% end %> <%= simple_form_for @user do |f| %> <%= f.input :name %> <%= f.input :email %> <%= f.input :birthday %> <%= f.button :submit %> <% end %>
  21. Use Ruby REPL everywhere Web Console

  22. carrierwave - Flexible Image Uploader kaminari - De facto paginator

    for Rails omniauth - Standardizes multi provider authentication redcarpet - Markdown parser and renderer Other useful gems
  23. None
  24. 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