Presentasjon lastes. Vennligst vent

Presentasjon lastes. Vennligst vent

Ruby on Rails: Making simple stuff simple “Rails is a full-stack, open-source web framework in Ruby for writing real-world applications with joy and less.

Liknende presentasjoner


Presentasjon om: "Ruby on Rails: Making simple stuff simple “Rails is a full-stack, open-source web framework in Ruby for writing real-world applications with joy and less."— Utskrift av presentasjonen:

1 Ruby on Rails: Making simple stuff simple “Rails is a full-stack, open-source web framework in Ruby for writing real-world applications with joy and less code than most frameworks spend doing XML sit-ups” –

2 Eksempel!

3 Copyright 2005 – Brodwall IT Services (BITS) Litt tall: Library | Name | Lines | LOC | Classes | Methods | M/C | LOC/M | | Helpers | 13 | 12 | 0 | 0 | 0 | 0 | | Controllers | 162 | 132 | 6 | 26 | 4 | 3 | | APIs | 0 | 0 | 0 | 0 | 0 | 0 | | Components | 0 | 0 | 0 | 0 | 0 | 0 | | Functionals | 309 | 224 | 10 | 38 | 3 | 3 | | Models | 82 | 65 | 4 | 9 | 2 | 5 | | Units | 176 | 143 | 4 | 24 | 6 | 3 | | Total | 742 | 576 | 24 | 97 | 4 | 3 | Code LOC: 209 Test LOC: 367 Code to Test Ratio: 1:1.8 Views: 27 filer (9 in use) (413 linjer), fordelt på 6 controllere, Arbeidstid: Cirka 2,5 timer

4 Copyright 2005 – Brodwall IT Services (BITS) Litt tall: Survey | Name | Lines | LOC | Classes | Methods | M/C | LOC/M | | Helpers | 17 | 16 | 0 | 0 | 0 | 0 | | Controllers | 317 | 266 | 6 | 52 | 8 | 3 | | APIs | 0 | 0 | 0 | 0 | 0 | 0 | | Components | 0 | 0 | 0 | 0 | 0 | 0 | | Functionals | 440 | 315 | 10 | 50 | 5 | 4 | | Models | 50 | 40 | 5 | 6 | 1 | 4 | | Units | 70 | 50 | 5 | 10 | 2 | 3 | | Total | 894 | 687 | 26 | 118 | 4 | 3 | Code LOC: 322 Test LOC: 365 Code to Test Ratio: 1:1.1 Views: 23 filer (376 linjer), fordelt på 5 controllere, Arbeidstid: Cirka 15 timer (inkludert fikling med doc og notater av alt jeg gjorde)

5 Rails på 5 minutter En enkel controller og view

6 Copyright 2005 – Brodwall IT Services (BITS) Rails på 5 minutter »rails library »cd library »start ruby script\server »start »ruby script\generate controller Say »start »scite app/controllers/say_controller.rb def hello; end (REFRESH) »scite./script/../config/../app/views//say/hello.rhtml HELLO WORLD (REFRESH) »scite app/views/say/hello.rhtml (ruby expressions) Dates: »scite app/controllers/say_controller.rb (verdier fra controller) def = = [ 'city', 'person', 'place' { |word| word.capitalize.pluralize } end »scite app/views/say/hello.rhtml (verdier fra controller) Dates:

7 Copyright 2005 – Brodwall IT Services (BITS) Linking »scite app/views/say/hello.rhtml Click here to say good bye »scite app/controllers/say_controller.rb def goodbye; end »scite./script/../config/../app/views//say/goodbye.rhtml Stop by and say hello again »hello.rhtml (fiks link) Click Stop by and "goodbye" %> to say good bye »goodbye.rhtml (fiks link) Stop by and "hello" %> again »routes.rb map.connect ':controller/:action/:id'

8 Copyright 2005 – Brodwall IT Services (BITS) Model-view-controller

9 Rails på 10 minutter En enkel scaffold En generert scaffold

10 Copyright 2005 – Brodwall IT Services (BITS) Setup database »scite config/database.yml »mysql -u root –p CREATE DATABASE my_development; GRANT ALL on my_development.* to »scite db/create.sql drop table if exists users; drop table if exists books; create table books ( id int primary key not null auto_increment, title varchar(100) not null, author varchar(100) ); create table users ( id int primary key not null auto_increment, username varchar(100) not null, full_name varchar(100) not null, password varchar(100), unique key (username) ); »mysql -u my my_development < db\create.sql

11 Copyright 2005 – Brodwall IT Services (BITS) Scaffold »ruby script/generate controller books »ruby script/generate model book »scite app/controllers/books_controller.rb scaffold :book »ruby script/generate scaffold user »Remove password »scite app/views/users/list.rhtml »scite app/views/users/show.rhtml

12 Copyright 2005 – Brodwall IT Services (BITS) Mer info

13 Copyright 2005 – Brodwall IT Services (BITS) Ajax •Er dette Ajax? –(Nei!!!) •Hva er AJAX? •For det samme i Java: •http://www.theserverside.com/articles/article.tss?l=AjaxinAction_CH4 _PT2http://www.theserverside.com/articles/article.tss?l=AjaxinAction_CH4 _PT2 var obj; function GetDataViaAJAX() { try { obj = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { obj = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e1) { obj = null; } if(obj!=null) { obj.onreadystatechange = ProcessResponse; obj.open("GET", "http://localhost/AJAXDemo/datasupplier.aspx? customerid=" + document.getElementById("DropDownList1").value, true); obj.send(null); } return false; } Fra Using AJAX with ASP.NET

14 Copyright 2005 – Brodwall IT Services (BITS) Ajax •Er dette Ajax? –Ja •Hva er AJAX? –Asykront –Interaktivt og –Komponentisert <%= link_to_remote "Loan history", :update =>:loan_history, :url => { :action => "show_history", :id } %>

15 Copyright 2005 – Brodwall IT Services (BITS) Diskusjon •Nå passer Rails? •Når passer Rails ikke? •Hva kan vi lære av Rails? •Hvordan kommer vi til å se "arven fra Rails" i framtiden? •Sammenligning med andre løsninger

16 Copyright 2005 – Brodwall IT Services (BITS) Når passer Rails? •Når du trenger mye “bang for the buck” •Når Rails stacken passer for dine behov •Når du kun har en web+mail applikasjon

17 Copyright 2005 – Brodwall IT Services (BITS) Når passer Rails mindre bra? •Når du trenger en moden (= utprøvd) teknologi •Når du regner med mye fikling –I18N –Performance –Legacy databaser •Når du må gjøre store utskiftinger i stacken •Når du ikke driver med web

18 Copyright 2005 – Brodwall IT Services (BITS) Validering class BookTitle < ActiveRecord::Base has_many :books validates_presence_of :title, :author validates_numericality_of :publication_year, :only_integer => true validates_presence_of :publication_year def validate if not publication_year.nil? publication_year > 1900 or errors.add(:publication_year, "should be after 1900") publication_year <= Time.now.year or errors.add(:publication_year, "should not be in the future") end

19 Copyright 2005 – Brodwall IT Services (BITS) Relasjoner class Question < ActiveRecord::Base belongs_to :survey has_many :survey_response_answers acts_as_list :scope => :survey has_many :options, :order => 'position‘ # options acts_as_list def to_s description end

20 Copyright 2005 – Brodwall IT Services (BITS) Hva kan vi lære av Rails •Convention over configuration –Default parametre –Default mapping –Default applikasjonsstack! •Gode kodegeneratorer er ikke onde

21 Copyright 2005 – Brodwall IT Services (BITS) Ruby POWER •Adding a method to null- pointers •TAKE THAT, C#! >> a = nil => nil >> a.hello NoMethodError: undefined method `hello' for nil:NilClass from (irb):4 >> class NilClass >> def hello; puts "help"; end >> end => nil >> a.hello help => nil


Laste ned ppt "Ruby on Rails: Making simple stuff simple “Rails is a full-stack, open-source web framework in Ruby for writing real-world applications with joy and less."

Liknende presentasjoner


Annonser fra Google