představení ruby on rails [junior internet]
DESCRIPTION
Představení a ukázka Ruby on Rails [www.rubyonrails.org] pro seminář pořádaný Junior Internet, Praha, 28. 9. 2009TRANSCRIPT
![Page 1: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/1.jpg)
Efektivní vývoj webových aplikacív Ruby On RailsKarel Minařík
![Page 3: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/3.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
Co je Ruby On Rails?1
![Page 4: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/4.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
Webový framework
![Page 5: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/5.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
Ruby On Rails je jedním z nejucelenějších popisů doporučených postupů pro moderní webový vývoja inspirací pro ostatní technologie a frameworky
![Page 6: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/6.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
![Page 7: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/7.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
Open source, licence MIT
![Page 8: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/8.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
www.rubyonrails.org
![Page 9: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/9.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
![Page 10: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/10.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
Basecamp
![Page 11: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/11.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
Basecamp
![Page 12: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/12.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
Surviving the Big Rewrite: Moving YELLOWPAGES.COM to RailsRailsConf 2008, http://en.oreilly.com/rails2008/public/schedule/detail/2082InfoQ, YELLOWPAGES.COM: Behind the Curtain, http://www.infoq.com/presentations/straw-yellowpages
Scaling TwitterSilicon Valley Ruby Conference 2007, http://www.slideshare.net/Blaine/scaling-twitter
![Page 13: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/13.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
http://www.infoq.com/presentations/straw-yellowpages
![Page 14: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/14.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
![Page 15: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/15.jpg)
— Jukihiro Macumoto (Matz)
![Page 16: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/16.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
Přednáška Ruby Design Principles, 2006 (včetně MP3 záznamu)
http://itc.conversationsnetwork.org/shows/detail1638.html
![Page 17: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/17.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
Ruby from Other Languageshttp://www.ruby-lang.org/en/documentation/ruby-from-other-languages/
![Page 18: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/18.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
Klíčové součásti Ruby On Rails
![Page 19: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/19.jpg)
Přehled
![Page 20: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/20.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
Přehled
Model—View—Controller„Konvence má přednost před konfigurací“
Jádro frameworku:1) Objektově relační mapování ActiveRecord
2) Směrování HTTP požadavků na řídící prvky aplikace ActionController a –View 3) Webové služby typu REST ActiveResource
4) Odesílání e-mailů ActionMailer
5) Rozšíření Ruby ActiveSupport
Generátory kódu, Rake tasky, Capistrano, konzole aplikace, …
Rails pluginy a Ruby gemy
![Page 21: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/21.jpg)
![Page 22: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/22.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
Model—View—Controller
![Page 23: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/23.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
Model–View–Controller
![Page 24: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/24.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
Adresářová struktura Rails aplikace
Model–View–Controller a „konvence má přednost před konfigurací“
controllers/articles_controller.rb
models/article.rb
views/articles/index, edit, new, atdviews/layouts/articles.html.erb
![Page 25: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/25.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
Generátory kódu
![Page 26: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/26.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
Generátory kódu
The Pragmatic Programmer: From Journeyman to Master, Andrew Hunt and David Thomas
Passive Code Generators Passive code generators save typing. They are basically parameterized templates, generating a given output from a set of inputs. Once the result is produced, it becomes a full-fledged source file in the project; it will be edited, compiled, and placed under source control just like any other file. Its origins will be forgotten.
(str. 87)
![Page 27: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/27.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
$ script/generate scaffold Person last_name:string date_of_birth:date
create app/models/person.rbcreate test/unit/person_test.rbcreate test/fixtures/people.ymlcreate db/migrate/20081007091729_create_people.rbcreate app/views/people/index.html.erbcreate app/views/people/show.html.erbcreate app/views/people/new.html.erbcreate app/views/people/edit.html.erb
create app/views/layouts/people.html.erbcreate app/controllers/people_controller.rbcreate test/functional/people_controller_test.rbcreate app/helpers/people_helper.rbroute map.resources :people
Generátory kódu
![Page 28: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/28.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
ActiveRecord
![Page 29: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/29.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
Objektově relační mapování — ActiveRecord
Martin Fowler, Patterns of Enterprise Application Architecture (2002)
![Page 30: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/30.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
ID Name Surname E-mail1 John Smith [email protected] Susanna Reddick [email protected]
tabulka people
INSERT INTO people (name, surname, email) VALUES( 'John', 'Smith', '[email protected]' );SELECT * FROM people;SELECT * FROM people WHERE id = 1;SELECT * FROM people WHERE surname = 'Smith';
# ActiveRecord::Base.establish_connection ...Person.create(:name => 'John', :surname => 'Smith', :email => '[email protected]')Person.allPerson.find(1)Person.find_by_surname('Smith')
Objektově relační mapování — ActiveRecord
![Page 31: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/31.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
Person.all :order => 'last_name DESC'
Person.all :conditions => "administrator = 1"
Person.all(:conditions => [ "department = :department AND position = :position", {:department => params[:department], :position => params[:position]} ] )
Person.all :include => 'accounts'
Person.all :group => 'country'
Person.find_by_sql( "SELECT id AS complicated ..." )
Objektově relační mapování — ActiveRecord
![Page 32: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/32.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
p = Person.find 1
p.first_name = 'Robert'
p.save
p.destroy
Objektově relační mapování — ActiveRecord
![Page 33: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/33.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
class Account < ActiveRecord::Base validates_presence_of :account_number, owner_id validates_numericality_of :balance validates_length_of :password, :minimum=> 4 validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i validates_acceptance_of :terms_of_service, :on => 'create' end
ActiveRecord — Validace
http://www.railsbrain.com/api/rails-2.1.0/doc/index.html?a=M001739&name=validates_presence_of
![Page 34: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/34.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
ActiveRecord — Callbacks
class Article < ActiveRecord::Base
after_save :clean_up_html after_destroy :audit_log
protected def clean_up_html self.body.gsub( ... ) end def audit_log audit_logger.info("Article #{self.title} has been removed by user #{current_user}") end end
http://www.railsbrain.com/api/rails-2.3.2/doc/index.html?a=M001715&name=after_save
![Page 35: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/35.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
ActiveRecord — Asociace
$ railroad -a -i -o full_models.dot -M
http://www.railsbrain.com/api/rails-2.3.2/doc/index.html?a=M001491&name=has_many
![Page 36: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/36.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
ActiveRecord — Asociace
class Project < ActiveRecord::Base belongs_to :project_manager end
create_table :projects do |t| t.string :title t.text :description t.integer :project_manager_id t.timestampsend
![Page 37: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/37.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
ActiveRecord — Asociace
class Project < ActiveRecord::Base belongs_to :project_manager, :class_name => "User" has_many :tasksend
class User < ActiveRecord::Base has_many :projects has_many :tasks, :foreign_key => 'assigned_to'end
class Task < ActiveRecord::Base belongs_to :project belongs_to :user, :foreign_key => "assigned_to" end
Convention over configuration
![Page 38: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/38.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
ActiveRecord — dočasné řešení
Dokumentově orientované databáze , key:value store, atd.
![Page 39: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/39.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
ActionController
![Page 40: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/40.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
Routing — ActionController
Rails 1.1
![Page 41: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/41.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
Routing — ActionController
Rails 1.1
![Page 42: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/42.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
ActionController::Routing::Routes.draw do |map| map.resources :peopleend
GET http://www.example.com/peopleGET http://www.example.com/people/1POST http://www.example.com/peoplePUT http://www.example.com/people/1DELETE http://www.example.com/people/1
Routing + Resources — ActionController
RESTful!
people_pathperson_path(1)
Rails 1.2.x
PeopleController#index()
PeopleController#show()
PeopleController#update()
PeopleController#destroy()
PeopleController#create()
![Page 43: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/43.jpg)
— DHH, RailsConf 2007 Keynote, „The World Of Resources“
RESTfulInner API
![Page 44: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/44.jpg)
— DHH, RailsConf 2007 Keynote, „The World Of Resources“
![Page 45: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/45.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
ActionController::Routing::Routes.draw do |map| map.resources :peopleend
GET http://www.example.com/peopleGET http://www.example.com/people/1POST http://www.example.com/peoplePUT http://www.example.com/people/1DELETE http://www.example.com/people/1
Routing + Resources — ActionController
RESTful!
people_pathperson_path(1)
Rails 1.2.x
PeopleController#index()
PeopleController#show()
PeopleController#update()
PeopleController#destroy()
PeopleController#create()
![Page 46: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/46.jpg)
— DHH, RailsConf 2007 Keynote, „The World Of Resources“
![Page 47: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/47.jpg)
— DHH, RailsConf 2007 Keynote, „The World Of Resources“
ActiveResource — ORM pro webové službyKLÍČOVÉ SOUČÁSTI RUBY ON RAILS
![Page 48: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/48.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
ActiveResource — ORM pro webové služby
class Person < ActiveResource::Base self.site = "http://username:[email protected]:3000/"end
# Expects a response of## <person><id type="integer">1</id><attribute1>value1</attribute1><attribute2>..</attribute2></person>## for GET http://api.people.com:3000/people/1.xml
ryan = Person.find(1)ryan = Person.new(:first => 'Ryan', :last => 'Daigle')ryan.save# => trueryan.id# => 2
![Page 49: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/49.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
ActionView
![Page 50: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/50.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
@person = Person.find params[:id]
<h2>Jméno: <%= @person.name %></h2><p>E-Mail: <%= mail_to @person.email %></p>
<hr />
<%= link_to "Seznam lidí", people_path %>
display.html.erb
people_controller.rb
ActionView
![Page 51: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/51.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
ActionView
Helpery pro formuláře, odkazy
<% form_for @person do |f| %> <%= f.text_field :name %> <%=f.datetime_select :date_of_birth %?<% end %>
<%= link_to @person.name, person_path(@person) %><a href="/person/show/1" ... />
Helpery pro Ajax, Scriptaculous, JavaScript
<%= link_to_remote "Skrýt", "update" => 'list', :url => { :action => 'hide' } %><a href ... onclick="new Ajax.Updater ... />
![Page 52: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/52.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
Automatizované testování
![Page 53: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/53.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
testovací data (fixtures)
testování controllerů a viewstestování modelů
Podpora pro automatizované testování aplikace v Rails
Podpora pro
![Page 54: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/54.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
Test::Unit (standardní knihovna Ruby)
require 'test/unit'
class MyTest < Test::Unit::TestCase # def setup # end
# def teardown # end
def test_true_is_true assert_equal(true, true, 'Assertion was false.') end
end
Automatizované testování aplikace: Unit Testing
![Page 55: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/55.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
Automatizované testování aplikace: Logika aplikace
class PersonTest < ActiveSupport::TestCase
# Replace this with your real tests. def test_truth assert true end
end
test/unit/person_test.rb
![Page 56: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/56.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
Automatizované testování aplikace: Testovací data
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
john: first_name: John last_name: Smith country: Great Britain department: Accounting position: Accountant administrator: true
robert: first_name: Roberto last_name: Callon country: Spain department: Marketing position: Graphic Designer administrator: false
test/fixtures/people.yml
![Page 57: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/57.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
class ProjectsControllerTest < ActionController::TestCase
def test_should_get_index get :index assert_response :success assert_not_nil assigns(:projects) end
end
Automatizované testování aplikace: Prezentační vrstva
http://www.railsbrain.com/api/rails-2.1.0/doc/index.html?a=C00000170&name=Assertions
test/functional/projects_controller_test.rb
![Page 58: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/58.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
class ProjectsControllerTest < ActionController::TestCase
def test_should_get_index get :index # HTTP odpoved (tedy "200 OK", nikoliv 302, 404, 403, 500, ...) assert_response :success # Naplnena promenna @projects assert_not_nil assigns(:projects) # Prave *dva* projekty assert_equal 2, assigns(:projects).size # Pouzita sablona assert_template "index" # <title> stranky assert_select "title", "Projekty" # Fragment HTML kodu assert_tag :tag => 'li', :attributes => { :id => "project_#{projects(:babylon).id}", :class => 'in_progress' } end
end
Automatizované testování aplikace: Příklady
http://www.railsbrain.com/api/rails-2.1.0/doc/index.html?a=C00000170&name=Assertions
![Page 59: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/59.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
Co jsme vynechali?
![Page 60: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/60.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
Databázové migrace
Nástroj Rake
Konzole aplikace (script/console)
Alternativní testovací frameworky
Pluginy a rozšíření Rails
Rozšíření jazyka Ruby (1.day.ago, "cat".pluralize, ...)
Cachování
Internacionalizace (Lokalizace)
Šablony pro skelet aplikace
…
Co jsme vynechali?
(Instalace pluginů, repositáře, vlastních nastavení, atd.)
![Page 61: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/61.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
Deployment Rails aplikací
![Page 62: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/62.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
WebserverApache, Nginx, …
MongrelZpracovává požadavky na Rails Statické soubory
Čte web server rovnou z disku a obchází Mongrel i Rails
DatabázeBěží na stejném nebo jiném serveru
Load Balancer( )Struktura Rails aplikace běžící v produkčním prostředí
reverse proxy
![Page 63: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/63.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
www.capify.org
$ cap -T$ cap deploy:migrations$ cap invoke 'cd /home/deployer/app/curent; grep -in error log/production.log'
Nástroj Capistrano pro efektivní deployment
![Page 64: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/64.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
Phusion Passenger (mod_rails, mod_rack, ap.)
$ gem install passenger$ passenger-install-apache2-module
![Page 65: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/65.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
http://free.railshosting.cz
![Page 66: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/66.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
Další zdroje a informace
![Page 67: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/67.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
Zdroje a informace
Peter Cooper, Beginning RubyApress 2007
Dave Thomas, David Heinemeier Hansson, et al.Agile Web Development With Ruby On Rails, 2nd editionPragmatic Bookshelf 2006 NEW říjen 2008
![Page 68: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/68.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
Zdroje a informace
Russ Olsen, Design Patterns in RubyPragmatic Bookshelf 2007
David Flanagan and Yukihiro Matsumoto, The Ruby Programming LanguagePragmatic Bookshelf 2007
Mike Naberezny and Derek DeVries, Rails for PHP DevelopersPragmatic Bookshelf, 2008
![Page 69: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/69.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
KLÍČOVÉ SOUČÁSTI RUBY ON RAILS
http://guides.rubyonrails.orgwww.railsinside.comwww.railscasts.comwww.ruby-lang.org/en/documentation/quickstartwww.rubyinside.com
http://forum.rubyonrails.cz#rubyonrails (IRC kanál na IRCNet)www.csrug.cz
Zdroje a informace
www.railsforphp.comhttp://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-php
![Page 70: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/70.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
Živá ukázka tvorby aplikace v Rails2
![Page 71: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/71.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
www.tadalist.com od 37Signals
![Page 72: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/72.jpg)
Efektivní vývoj webových aplikací v RubyOnRails
create app/controllers create app/helpers create app/models create app/views/layouts create config/environments create config/initializers create db create doc create lib create lib/tasks create log create public/images create public/javascripts create public/stylesheets create script/performance create script/process create test/fixtures create test/functional create test/integration create test/mocks/development create test/mocks/test create test/unit create vendor create vendor/plugins create tmp/sessions create tmp/sockets create tmp/cache
$ sudo gem install rails$ rails -v$ rails planner
Ukázka
![Page 73: Představení Ruby on Rails [Junior Internet]](https://reader033.vdocuments.site/reader033/viewer/2022052823/555303adb4c905533f8b47fe/html5/thumbnails/73.jpg)
Děkuji!
www.karmi.cz