Contagion的Ruby/Rails投影片

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite

    Contagion的Ruby/Rails投影片 - Presentation Transcript

    1. RUBY on OSDC.TW 2006
    2. contagious
    3. How Hot is RoR
    4. 450,000 over 400,000 downloads 337,500 225,000 112,500 0 2004 July 2004 Dec. 2005 Oct. 2006 April
    5. • 400 seats, sold out in one week • extra 150 seats, sold out in 24 hours
    6. David Heinemeier Hansson
    7. Data from BookScan: Ruby Books sales is up 1,552% over last year.
    8. RoR is so HOT Everybody wants to clone it
    9. What exactly is Ruby On Rails
    10. Ruby on Rails is an open-source web framework
    11. optimized for programmer happiness
    12. What Makes Programmer Happy? • Simplicity • Well organized • Easy to learn • Easy to Maintain • Easy to Write
    13. SIMPLE Easy to Learn and Write No separation between Business Logic and Display Logic
    14. Corporate Approval Well Structured Steep Learn Curve Complex Configuration No fast turnaround
    15. Finding the middle ground with
    16. Full Stack of MVC
    17. Real World Usage
    18. One Language - Ruby • Model - View - Controller • Database Schema generation • Javascript generation • XML generation • Makefile
    19. Convention Over Configuration
    20. CREATE TABLE orders ( id INTEGER PRIMARY KEY AUTO_INCREMENT, An order_date TIMESTAMP NOT NULL, price_total DOUBLE NOT NULL ); example CREATE TABLE products ( id INTEGER PRIMARY KEY AUTO_INCREMENT, from a name VARCHAR(80) NOT NULL, price DOUBLE NOT NULL ); Hibernate CREATE TABLE order_items ( id INTEGER PRIMARY KEY AUTO_INCREMENT, tutorial order_id INTEGER NOT NULL, product_id INTEGER NOT NULL, amount INTEGER NOT NULL, price DOUBLE NOT NULL );
    21. public class Order Java { private Integer id; private Date date; private double priceTotal; Object private Set orderItems = new HashSet(); public Order() { Model: this.date = new Date(); } public Integer getId() { Order return id; } public void setId(Integer id) { this.id = id; } public Date getDate() { return date; } public void setDate(date) { this.date = date; } public void addProduct(Product p, int amount) { OrderItem orderItem = new OrderItem(this, p, amount); this.priceTotal = this.priceTotal + p.getPrice() * amount; this.orderItems.add(orderItem); } }
    22. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"> Java <hibernate-mapping> <class name="test.hibernate.Order" table="orders"> <id name="id" type="string" unsaved-value="null" > <column name="id" sql-type="integer" not-null="true"/> Database <generator class="native"/> </id> <property name="date"> Mapping: <column name="order_date" sql-type="datetime" not-null="true"/> </property> Order <property name="priceTotal"> <column name="price_total" sql-type="double" not-null="true"/> </property> <set name="orderItems" table="order_items" inverse="true" cascade="all"> <key column="order_id" /> <one-to-many class="test.hibernate.OrderItem" /> </set> </class> </hibernate-mapping>
    23. Rails Data Model: Order class Order < ActiveRecord::Base has_many :order_items def add_product(product, amount) order_item = OrderItem.new(product, amount) self.price_total += product.price * amount order_items << order_item end end
    24. "opinionated software" — sacrificing some flexibility in favour of simplicity
    25. “much greater productivity and a better developer experience”
    26. Dispatch based on URLs http://myapp/orders/show/1 Application controller action id *customizable by Routing
    27. Action grouped in Controller class OrdersController < ApplicationController def index list # Default to app/views/orders/index.rhtml render :action => 'list' end def list @order_pages, @orders = paginate :orders, :per_page => 10 end def show @order = Order.find(params[:id]) end end
    28. Rendering and Redirection def update @order = Order.find(params[:id]) if @order.update_attributes(params[:order]) flash[:notice] = 'Order was successfully updated.' redirect_to :action => 'show', :id => @order else render :action => 'edit' end end
    29. Query Data the_order = Order.find(2) book = Product.find_by_name(”Programming Ruby”) small_order = Order.find :first, :condition => [”price_total <= ?”, 50.0] web_books = Product.find :all, :condition => [”name like ?”,”%Web%”] print book.name print the_order.price_total
    30. Associations class Order < ActiveRecord::Base has_many :order_items end the_order = Order.find :first the_oder.oder_items.each do |item| print item.name end * Some other associations: has_one, belongs_to, has_and_belongs_to_many...
    31. Validations class Product < ActiveRecord::Base validates_presenc_of :name validtaes_numericality :price end Hooks class Order < ActiveRecord::Base def before_destory order_items.destory_all end end
    32. Views - Erb <!-- app/views/product/list.rhtml --> <% for product in @products -%> <p> <ul> <li> name: <%= product.name %> </li> <li> price: <%= product.price %> </li> </ul> <%= link_to 'Show', :action => 'show', :id => product %> </p> <% end -%>
    33. Sounds Great !! But it is written in .... ?? Ruby ??
    34. Rails makes it fast to develop, but the true power behind Rails is RUBY
    35. Blocks • Iteration 5.times { |i| puts i } [1,2,3].each { |i| puts i } • Resource Management File.open(’t.txt’) do |f| #do something end • Callback TkButton.new do text “EXIT” command { exit} end
    36. New Language Construct Rakefile task :test => [:compile, :dataLoad] do # run the tests end Markaby html do body do h1 ‘Hello World’ end end
    37. Dynamic Nature •Open Class • Runtime Definition • Code Evaluation • Hooks
    38. Meta - Programming class Order < ActiveRecord::Base has_many :order_items end class Product < ActiveRecord::Base validates_presenc_of :name validtaes_numericality :price end
    39. Syntax Matters • Succinct • Easy to Read • Principle of Least Surprise
    40. Ruby is designed to make programmers Happy
    41. Where Rails Sucks •Internationalization • Speed • Template System • Stability • Legacy System
    42. Lack Resources In Taiwan
    43. Join Ruby.tw http://willh.org/cfc/wiki/
    44. Q&A

    + cfccfc, 3 years ago

    custom

    2042 views, 1 favs, 2 embeds more stats

    有點舊了:P

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 2042
      • 2036 on SlideShare
      • 6 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 116
    Most viewed embeds
    • 5 views on http://www.lonerunners.net
    • 1 views on http://209.85.165.104

    more

    All embeds
    • 5 views on http://www.lonerunners.net
    • 1 views on http://209.85.165.104

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories