Ruby on 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

    Favorites, Groups & Events

    Ruby on Rails : 簡介與入門 - Presentation Transcript

    1. Ruby on Rails Part1: ihower@gmail.com http://creativecommons.org/licenses/by-nc/2.5/tw/
    2. • (a.k.a ihower) http://ihower.idv.tw/blog/
    3. • (a.k.a ihower) http://ihower.idv.tw/blog/ • http://handlino.com
    4. • (a.k.a ihower) http://ihower.idv.tw/blog/ • http://handlino.com
    5. Rails? • ( MIT ) Web database-backed • MVC (Model-View-Control ) • ( ) Ruby Ajax ORM (object-relational-mapping) • 2004 David Heinemeier Hanson(DHH) 37signals
    6. • Ruby • Don’t Repeat Yourself (DRY) • • • Convention Over Configuration • •
    7. Ruby on Rails ? • ( ) • ( Joomla Durpal CMS •
    8. Rails • 2005 DHH Hacker • 2006 Rails Jolt • 2005~2006 Ruby/Rails 1552% • Ruby Tiobe 26 10
    9. Rails ? Java(Spring/Hibernate) Rails 4 20 4 ( 5 ) 3293 1164 1161 113 / 62/549 55/126 Justin Gehtland Java Rails
    10. Rails ? • Justin Gehtland Java :Rails = 3.5 : 1 • Proc.net PHP : Rails = 10 : 1 • JavaEye JAVA : Rails = 10 : 1 • thegiive PHP : Rails = 8 : 1
    11. Rails clone
    12. Rails ? M V C MVC Model-View-Control
    13. DB schema Ruby class CreatePeople < ActiveRecord::Migration def self.up create_table :people do |t| t.string :name t.integer :age t.date :birthday t.text :bio t.timestamps end end def self.down drop_table :people end end
    14. Active Record ORM class Person < ActiveRecord::Base # end person = Person.new person.name "ihower" person.age = 18 person.save person = Person.find(1) puts person.name # ihower
    15. Action Controller HTTP request class PeopleController < ApplicationController # GET /people def index @people = Person.all end end
    16. Action Controller HTTP request class PeopleController < ApplicationController method action # GET /people def index @people = Person.all end end
    17. Action Controller HTTP request class PeopleController < ApplicationController method action # GET /people def index @people = Person.all end instance variable end View
    18. Action View Ruby HTML <html> <body> <h1>Guestbook</h1> <% @people.each do |person| %> <p><%= person.name %>: <%= person.bio %></p> <% end %> </body> </html>
    19. Why Rails? • • • (prototyping) • •
    20. Because Rails is ... • MVC • (Ajax RESTful ) • • • • Ruby ( ) • ActiveRecord ORM • Migration • (DRY)
    21. Thank you. Get to the Point! (http://johnwlong.com/slides/gettothepoint/) Ruby on Rails slide by thegiive in COSCUP Delivery of the key adoption Factors and key characteristics of companies using ruby on rails by Michel Barbosa
    22. Ruby on Rails Part2: ihower@gmail.com http://creativecommons.org/licenses/by-nc/2.5/tw/
    23. README • http://ihower.idv.tw/blog/archives/1743 • http://ihower.idv.tw/course/rails.html
    24. Web framework? • • Perl CGI PHP ASP MVC Database URL Template Cookie Ajax .... • Framework Framework
    25. MVC? • Model Controller View • Model • • View • Ruby HTML • Controller Model • (e.g. ) Request Model View (e.g. HTML)
    26. 1. Controller 2. 3. 4. View Model DB
    27. Rails MVC? Routing 1. 2. ActionController 4. 3. 5. ActionView ActiveRecord DB
    28. MVC? • • (DRY: Don’t repeat yourself) •
    29. Ruby on Rails • Ruby 1.8.6 1.8.7 • Rubygems (Ruby ) • Rails SQLite 3 MySQL Postgres Oracle DB2 MSSQL
    30. Rails Hello World!(live demo & )
    31. (Routes) http://localhost:3000/welcome/say Controller Action # /config/routes.rb map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format'
    32. Model (live demo)
    33. ORM ? • ActiveRecord Rails ORM • ORM: Object-Relational Mapping • (table) (classe) • • (row) (object) • • (column) (object attribute)
    34. script/console ORM ( )
    35. script/* ? • script/about • script/console • script/generate • script/server • script/plugin
    36. Rake? • Make Ruby • # lib/tasks/my_task.rake namespace :my desc "task description" task :foo_task => :environment do puts “foobarrrr” end end rake my:foo_task
    37. Rake ? • rake -T • rake db:migrate • rake db:drop • rake tmp:clear • rake notes
    38. DB Migration? • Ruby (Schema) • • e.g. ?? • • e.g. SQLite3 MySQL Postgres...etc • Migration
    39. Rails • app • log • controllers • public • helpers • script • models • test • views • tmp • config • vendor • db • doc • lib
    40. Rails environments • development, production, test mode • • Log level Session store, custom library, Email setting • environment
    41. controller view (live demo & )
    42. controller view (live demo & )
    43. controller view (live demo & )
    44. controller view (live demo & )
    45. Helper ? • view template helper method • link_to • form_for •h (XSS ) • /app/helpers/* Helper
    46. Layout (live demo & ) • View Layout HTML • /app/views/layouts/application.html.erb
    47. flash hash (live demo & ) • flash hash redirect action •
    48. DRY: Partial template (live demo & ) • View •
    49. DRY: before_filter (live demo & ) • Controller • ID Model
    50. Model Validation (live demo & ) • post.rb validates_presence_of :title • new.html.erb edit.html.erb <%= error_messages_for :post %> helper
    51. Thank you. Agile Web Development with Rails 3rd. RailsGuides http://guides.rubyonrails.org

    + Wen-Tien ChangWen-Tien Chang, 2 months ago

    custom

    453 views, 0 favs, 2 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 453
      • 362 on SlideShare
      • 91 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 29
    Most viewed embeds
    • 88 views on http://ihower.idv.tw
    • 3 views on http://ihower.tw

    more

    All embeds
    • 88 views on http://ihower.idv.tw
    • 3 views on http://ihower.tw

    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?