6회 루비세미나 튜토리얼 세션에서 발표한 내용입니다.
URL
EMBED
Page 0:
Page 1: ~
deepblue @ openmaru
http://myruby.net/
Page 2: Person.new 'deepblue', :rubykr => 5.years, :write => 'myruby.net', :develop => 'springnote'
http://www.flickr.com/photos/ucumari/2401057328/
Page 3: Agenda
• • • • •
Page 4:
Page 5:
Page 6: Ruby on Rails is an open-source web framework that’s optimized for programmer happiness and sustainable productivity. It lets you write beautiful code by favoring convention over configuration.
Page 7:
Page 8:
Page 9: “Now, web designers and software engineers can develop a website much faster and more simply, enabling them to be more productive and effective in their work.”
Page 10: http://www.flickr.com/photos/adrianruiz/2116494509
Page 11: http://www.flickr.com/photos/drachmann/327122302/
Page 12: ~
http://www.flickr.com/photos/eyefruit/179553810/
Page 13: ~
http://www.flickr.com/photos/eyefruit/179553810/
Page 14: ~
http://www.flickr.com/photos/eyefruit/179553810/
Page 15: http://www.flickr.com/photos/flattop341/1085739925
Page 16: ?
. . . .
http://www.flickr.com/photos/flattop341/1085739925
Page 17: http://railsenvy.com/
Page 18: 5% 6%
31% 15%
16%
26%
Page 19: 5% 6%
31% 15%
16%
26%
Page 20: !
http://www.flickr.com/photos/dacotahsgirl/299198494/
Page 21: !
# 12.kilobytes == 12288.bytes
1.month.from_now #=> Mon Jul 28 18:00:00 +0900 2008 2.years.ago #=> Wed Jun 28 18:00:00 +0900 2006
"apple".pluralize #=> "apples" 'ActionController'.underscore #=> "action_controller"
w(1 2 3 4 5 6 7).in_groups_of(3) #=> [%w(1 2 3), %w(4 5 6), %w(7)]
http://www.flickr.com/photos/dacotahsgirl/299198494/
Page 22: !
# {:a=>1}.to_xml #=> ".. <a type=\"integer\">1</a>..." {:a=>1}.to_json #=> "{\"a\": 1}" # "
".chars.length #=> 2
# Time.zone = 'Hawaii' #=> "Hawaii" Time.zone.now #=> Wed Jun 28 18:00:00 -1000 2006 # ActiveSupport::Cache.lookup_store, :mem_cache_store, 'localhost'
http://www.flickr.com/photos/dacotahsgirl/299198494/
Page 23: Domain Specific Language
Do not Repeat Yourself
http://www.flickr.com/photos/dacotahsgirl/299198494/
Page 24:
Page 25: An object that wraps a row in a database table or view, encapsulates the database access, and adds domain logic on that data
http://martinfowler.com/eaaCatalog/activeRecord.html
Page 26: deepblue% script/console Loading development environment (Rails 2.1.0)
Page 27: deepblue% script/console Loading development environment (Rails 2.1.0)
class Person < ActiveRecord::Base end
Page 28: deepblue% script/console Loading development environment (Rails 2.1.0)
class Person < ActiveRecord::Base end >> Person => Person(id: integer, identity_url: string, nickname: string, email: string) >> person = Person.first => #<Person id: 1, identity_url: "http://deepblue.myid.net/", nickname: "deepblue", email: nil> >> person.nickname => "deepblue"
Page 29: deepblue% script/console Loading development environment (Rails 2.1.0)
class Person < ActiveRecord::Base end >> Person => Person(id: integer, identity_url: string, nickname: string, email: string) >> person = Person.first => #<Person id: 1, identity_url: "http://deepblue.myid.net/", nickname: "deepblue", email: nil> >> person.nickname => "deepblue"
Convention over Configuration
Page 30: Naming - File, Class, Table DB Mapping Directory Structure Request Dispatching View Rendering
http://www.flickr.com/photos/psilver/461848858/
Page 31: before_create :record_signup belongs_to has_one has_many :portfolio :project_manager :milestones
validates_acceptance_of :terms_of_service validates_inclusion_of :age, :in => 0..99 acts_as_tree :order => "name"
Page 32: HTTP Verb + URI + format GET GET GET /pages/1 # PagesController#show(:id => 1) /pages/1.xml # Page.find(1).to_xml /pages/1.iphone # /app/views/pages/show.iphone.*
POST /pages.iphone # PagesController#create(:page => {}) PUT /pages/1.json # PagesController#update DELETE /pages/1 # PagesController#destroy
http://www.flickr.com/photos/blion/789123423
Page 33: class PagesController < ApplicationController before_filter :login_requred after_filer :gzip
# GET /pages/:id.:format
def show @page = Page.find(params[:id]) respond_to do |format| format.html format.xml { render :xml => @page } format.iphone { skip_gzip } end end
http://www.flickr.com/photos/blion/789123423
Page 34: ~ Template
/app/views/:controller/:action.format.render
/pages/show.html.erb /pages/show.xml.builder /pages/show.iphone.haml /pages/_footer.html.liquid
http://www.flickr.com/photos/blion/789123423
Page 35: !
prompt> gem install ruby-openid prompt>
script/plugin install
svn://rubyforge.org/var/
svn/springnote/plugins/open_id_authentication prompt> script/generate open_id_store_migration AddOpenIdStore prompt> rake db:migrate prompt> script/generate open_id_consumer_controller session map.resource :session, :collection => {:begin => :any, :complete => :any}
http://www.flickr.com/photos/ppdigital/2058130092
Page 36: Red Green Refactor!
# bowling_spec.rb require 'bowling' describe Bowling do before(:each) do @bowling = Bowling.new end it "should score 0 for gutter game" do 20.times { @bowling.hit(0) } @bowling.score.should == 0 end end
http://www.flickr.com/photos/asurroca/55367485/
Page 37: rails my_first_rails_app # 30% script/generate resource .. # 50% 24
http://www.flickr.com/photos/flattop341/1085739925
Page 38: rails my_first_rails_app # 30% script/generate resource .. # 50% 24
http://www.flickr.com/photos/flattop341/1085739925
Page 39: http://www.flickr.com/photos/nexus_6/339726862
Page 40: http://www.flickr.com/photos/drachmann/327122302/
Page 41:
Page 42:
Page 43:
Page 44: fin.
http://myruby.net/
by deepblue
Page 45: