RUBYand Rails            BrisbaneRails.com
AgendaBackground          Ruby 101Why Ruby            Interactive DemoRuby Community      RailsEnvironments        Fundame...
Nigel Rausch@nr99http://au.linkedin.com/in/nigelrauschnigelr@brisbanerails.com                                        Bris...
PHP Years            BrisbaneRails.com
PHP Years1997 - 2003                     BrisbaneRails.com
PHP Years1997 - 2003Developed own framework                          BrisbaneRails.com
PHP Years1997 - 2003Developed own frameworkISP Management ( > $2.5M )                             BrisbaneRails.com
PHP Years1997 - 2003Developed own frameworkISP Management ( > $2.5M )Semi Retired in 2003                             Bris...
Got Bored            BrisbaneRails.com
Got BoredBack to code in 2005                       BrisbaneRails.com
Got BoredBack to code in 2005PHP didn’t do it for me                          BrisbaneRails.com
Got BoredBack to code in 2005PHP didn’t do it for meRuby on Rails (what weird name)                                  Brisb...
Got BoredBack to code in 2005PHP didn’t do it for meRuby on Rails (what weird name)Considered PHP equivalents             ...
Ruby on RailsStarted  Rails 1Considered PHP frameworks                            BrisbaneRails.com
Why Ruby           BrisbaneRails.com
Why Ruby           BrisbaneRails.com
Why Ruby           BrisbaneRails.com
More Why                        Rubyecho $this->Html->link($post[Post][title],array(controller => posts, action => view,$p...
More Why                           Rubyecho $this->Html->link($post[Post][title],array(controller => posts, action => view...
More Why                           Rubyecho $this->Html->link($post[Post][title],array(controller => posts, action => view...
More Why                           Rubyecho $this->Html->link($post[Post][title],array(controller => posts, action => view...
Why RailsRuby is descriptive clean languageLatest conceptsMigrations                                     BrisbaneRails.com
What’s RailsRails is built on RubyRails is a frameworkRails adds lots of DSLs and extra methods toRubyRails uses some of t...
CommunityRuby and Rails community is strong &supportive!Approx. 20 conferences a year  US, Ireland, Japan, Singapore, .......
Brisbane Ruby & Rails       Meetupwww.meetup.com/brisbane-ruby-rails/                                      BrisbaneRails.com
RailsCampBi-Annual event in Australia  Now in NZ, Europe and USStarts Friday afternoon  What happens at Railscamp stays......
RAILSCAMPs  100+ Ruby Devs                   BrisbaneRails.com
BrisbaneRails.com
Next RailsCamp is   June, 15th                    BrisbaneRails.com
Local ActivitiesActionHack1st Saturdayhttp://www.meetup.com/BrisJelly                                  BrisbaneRails.com
Work OpportunitiesRuby on Rails developers are in high demand  $60K - $120+K (more overseas)  $600 - $1200/day freelance  ...
Perception of Ruby Community                          BrisbaneRails.com
Ruby PerceptionCult statusSacrifice goats in the search for clean code                                         BrisbaneRail...
Ruby Perception (Actual)  Very supportive community  Very opinionated community  Very sharing (gems/code/blogs)  Very qual...
EnvironmentsMac  InstalledWindows  New installersLinux  Easy                        BrisbaneRails.com
Rubies Implementations Ruby MRI REE JRuby Rubinius IronRuby MacRuby                     BrisbaneRails.com
RVMRuby Version ManagerAllows multiple implementationsAllows multiple versions of implementationsEasy swap around and gem ...
ServerBEFORE  fast-cgi with reverse proxiesNOW  Passenger (mod rails)  heroku.com                                  Brisban...
Real World Web AppsAmerican Yellow PagesTwitterHuluSlidesharegithubRedbubbleIPHONE APIS                        BrisbaneRai...
ToolsCapistranoCucumberRspecAutoTest                     BrisbaneRails.com
GemsRubyGems is a package manager for theRuby programming language that provides astandard format for distributing Rubypro...
BrisbaneRails.com
BrisbaneRails.com
BrisbaneRails.com
IRB      BrisbaneRails.com
Ruby 101           BrisbaneRails.com
Interpreted                         Ruby No compilation Interactive Mode                    > ruby app.rb                 ...
No Type Casting                               Ruby No Type declarations                        value = 1                  ...
Everything is an object             Ruby     puts 99.class        -> Fixnum     puts “hello”.class   -> String     puts ni...
Skip parenthesis                    Ruby Most of the time Easier to read     puts “hello” DSL friendly       puts(“hello”)...
Variables                            Ruby Constant Local      VAR     =   “constant” Instance   var     =   “local”       ...
Naming Conventions                              Ruby underscore separated - variables and methods   full_name All Caps - c...
Basic Data Types    Ruby Numbers Strings Arrays Hashes Symbols true, false, nil                    BrisbaneRails.com
Numbers                               Ruby Integer Float            5 / 3   -> 1 Autoconversion   5.0 / 3 -> 1.66666....  ...
Arrays                                 Ruby 0 indexed arrays               var = [ 1, 2, 3]               var[1]       -> ...
Hashes                                 Ruby Ordered named arraysvar = {:name => “Fred”, “age” => 21}puts var[:name]       ...
Symbols                                Ruby Identifier Not assignable   {:password => “secret”} Mainly used in hashes      ...
true, false, nil               Ruby             good    = true             bad     = false             unknown = nil      ...
falsies                               Ruby nil and false everything else is true                     var = 0 0 => true    ...
Assignment                     Ruby             value = “hello”             a = 10             a += 1        => 11        ...
Conditions                                Ruby If statement                   if name == “Fred” Unless (invert)     put “H...
Conditions                                  Ruby Single line conditions                      var = true                   ...
Methods                              Rubydef say_hello  puts “hello”endsay_hello        -> “hello”def my_name_is name  “my...
Classes                                 RubyClass MyThing  def initialize name    @name = name  end  attr_accessor :name, ...
Iterator and blocks                    Ruby5.times do  puts “Nice for-loop, eh?”end5.times { puts “One-liner block form” }...
Iterators                             Rubyitems = [“good”, “great”, “superb”]                                      Brisban...
Iterators                             Rubyitems = [“good”, “great”, “superb”]for item in items  puts itemend              ...
Iterators                             Rubyitems = [“good”, “great”, “superb”]for item in items  puts itemenditems.each do ...
Iterators                             Rubyitems = [“good”, “great”, “superb”]for item in items  puts itemenditems.each do ...
Iterator - Map                        Rubyitems = [“good”, “great”, “superb”]build = []items.each do |item|  build << item...
Iterator       - select               Rubyitems = [“good”, “great”, “superb”]items.select do |item|  item.include? “e”end-...
Blocks                           Rubydef say_something  yield  yield  yieldendsay_something { puts "Hello" }HelloHelloHell...
Testing                               Rubyrequire test/unitdef my_name_is name  “my name is “ + nameendclass TestIt < Test...
Testing - RSpec                      Rubyrequire rspecdef greeting name  “my name is “ + nameenddescribe Greeting  it “sho...
Demo and Break                 BrisbaneRails.com
Ruby on Rails                BrisbaneRails.com
Ruby on Rails                BrisbaneRails.com
Ruby on RailsConvention over configuration                               BrisbaneRails.com
Ruby on RailsConvention over configurationDRY - Don’t Repeat Yourself                               BrisbaneRails.com
Ruby on RailsConvention over configurationDRY - Don’t Repeat YourselfMVC - Model View Controller                           ...
Ruby on RailsConvention over configurationDRY - Don’t Repeat YourselfMVC - Model View ControllerORM - Object Relation Mappi...
Ruby on RailsConvention over configurationDRY - Don’t Repeat YourselfMVC - Model View ControllerORM - Object Relation Mappi...
Ruby on RailsConvention over configurationDRY - Don’t Repeat YourselfMVC - Model View ControllerORM - Object Relation Mappi...
Convention over     ConfigurationConsistent StructureNaming conventions  Controller names -> Model names  Model names -> ta...
Don’t Repeat Yourself        DRYOne copy of a methodRe-usable methodspartial forms                       BrisbaneRails.com
Model View Controller        MVC1979 conceptController managesactionModel connects to DBViews separated fromlogicRouter   ...
Controller                                                    Railsclass CompaniesController < ApplicationController  def ...
View - Index                                             Rails<table>  <tr>    <th>Name</th>    <th>Website</th>  </tr>  <...
View - Index .haml                                       Rails%table  %tr    %th Name    %th Website  - for company in @co...
View - Form                          Rails<%= form_for @company do |f| %>  <%= f.error_messages %>  <p>    <%= f.label :na...
Model                                 Railsclass Company < ActiveRecord::Base  attr_accessible :name, :website  has_many :...
What’s ORMObject-Relational mapping is a programmingtechnique for converting data betweenincompatible type systems in data...
Quick Example #1select *from companieswhere id = 12item = Company.find(12)                         BrisbaneRails.com
Quick Example #2select *from companieswhere name = “Logical”item = Company.find_by_name(“Logical”)ORItem = Company.where(:n...
Quick Example #3update companiesset name = “Logical Plus”where id = 12item=Company.find(12)item.name = “Logical Plus”item.s...
Quick Example #4insert into companies (name, postcode)values (“Logical”, 4121)item=Company.newitem.name = “Logical”item.po...
Model  class Company < ActiveRecord::Base    has_many :contacts    has_many :invoices  end  class Contact < ActiveRecord::...
Migrationscreate and modify table and fields fromwithin code baseEasy deploymentReversible                                 ...
RestfulRepresentational State TransferConcept of Resources7 Resourcesindex, show, edit, update, new, create,destroyHTTP ve...
Rails Routes   companies_path GET    /companies(.:format)          :action=>"index”     company_path GET    /companies/:id...
Preparation              BrisbaneRails.com
Confirm Environmentruby -vgem -vrails -v                     BrisbaneRails.com
Rails Generationrails new my_app_namecd my_app_namerails generate ......rails console                        BrisbaneRails...
Let’s go build something!                       BrisbaneRails.com
Nigel Rausch     Thank you@nr99http://au.linkedin.com/in/nigelrauschnigelr@brisbanerails.com                              ...
Upcoming SlideShare
Loading in...5
×

Griffith uni

911

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
911
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • Basic, Assembly, C programmer\nThen the webdev came along\n\n- PHP\n - ISP Mgnt (millions)\n - Credit Card\n\n\n
  • Basic, Assembly, C programmer\nThen the webdev came along\n\n- PHP\n - ISP Mgnt (millions)\n - Credit Card\n\n\n
  • Basic, Assembly, C programmer\nThen the webdev came along\n\n- PHP\n - ISP Mgnt (millions)\n - Credit Card\n\n\n
  • Basic, Assembly, C programmer\nThen the webdev came along\n\n- PHP\n - ISP Mgnt (millions)\n - Credit Card\n\n\n
  • The feeling was gone.... So started looking at alternatives\n
  • The feeling was gone.... So started looking at alternatives\n
  • The feeling was gone.... So started looking at alternatives\n
  • The feeling was gone.... So started looking at alternatives\n
  • \n
  • Less code the easier to read \nless errors\n
  • Less code the easier to read \nless errors\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • We currently doing Ruby from the ground up\n
  • - multi-language coding \n - ruby/raisl\n - coffeescript\n - etc\n\n\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • PHP was hard to deploy in the 90s before modphp\n
  • IPHONE API&amp;#x2019;s\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Key matters\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • All the same\n
  • All the same\n
  • All the same\n
  • All the same\n
  • All the same\n
  • both cases build would contain the result\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Griffith uni

    1. 1. RUBYand Rails BrisbaneRails.com
    2. 2. AgendaBackground Ruby 101Why Ruby Interactive DemoRuby Community RailsEnvironments FundamentalsGems Build sample app BrisbaneRails.com
    3. 3. Nigel Rausch@nr99http://au.linkedin.com/in/nigelrauschnigelr@brisbanerails.com BrisbaneRails.com
    4. 4. PHP Years BrisbaneRails.com
    5. 5. PHP Years1997 - 2003 BrisbaneRails.com
    6. 6. PHP Years1997 - 2003Developed own framework BrisbaneRails.com
    7. 7. PHP Years1997 - 2003Developed own frameworkISP Management ( > $2.5M ) BrisbaneRails.com
    8. 8. PHP Years1997 - 2003Developed own frameworkISP Management ( > $2.5M )Semi Retired in 2003 BrisbaneRails.com
    9. 9. Got Bored BrisbaneRails.com
    10. 10. Got BoredBack to code in 2005 BrisbaneRails.com
    11. 11. Got BoredBack to code in 2005PHP didn’t do it for me BrisbaneRails.com
    12. 12. Got BoredBack to code in 2005PHP didn’t do it for meRuby on Rails (what weird name) BrisbaneRails.com
    13. 13. Got BoredBack to code in 2005PHP didn’t do it for meRuby on Rails (what weird name)Considered PHP equivalents BrisbaneRails.com
    14. 14. Ruby on RailsStarted Rails 1Considered PHP frameworks BrisbaneRails.com
    15. 15. Why Ruby BrisbaneRails.com
    16. 16. Why Ruby BrisbaneRails.com
    17. 17. Why Ruby BrisbaneRails.com
    18. 18. More Why Rubyecho $this->Html->link($post[Post][title],array(controller => posts, action => view,$post[Post][id])); BrisbaneRails.com
    19. 19. More Why Rubyecho $this->Html->link($post[Post][title],array(controller => posts, action => view,$post[Post][id]));link_to post.title, :controller => “posts”, :action => “view”, :id => post.id BrisbaneRails.com
    20. 20. More Why Rubyecho $this->Html->link($post[Post][title],array(controller => posts, action => view,$post[Post][id]));link_to post.title, :controller => “posts”, :action => “view”, :id => post.idlink_to post.title, post_path(post) BrisbaneRails.com
    21. 21. More Why Rubyecho $this->Html->link($post[Post][title],array(controller => posts, action => view,$post[Post][id]));link_to post.title, :controller => “posts”, :action => “view”, :id => post.idlink_to post.title, post_path(post)link_to post.title, post BrisbaneRails.com
    22. 22. Why RailsRuby is descriptive clean languageLatest conceptsMigrations BrisbaneRails.com
    23. 23. What’s RailsRails is built on RubyRails is a frameworkRails adds lots of DSLs and extra methods toRubyRails uses some of the advanced features ofRuby to hide the complicated stuff BrisbaneRails.com
    24. 24. CommunityRuby and Rails community is strong &supportive!Approx. 20 conferences a year US, Ireland, Japan, Singapore, ......Very Active IRCVery active development BrisbaneRails.com
    25. 25. Brisbane Ruby & Rails Meetupwww.meetup.com/brisbane-ruby-rails/ BrisbaneRails.com
    26. 26. RailsCampBi-Annual event in Australia Now in NZ, Europe and USStarts Friday afternoon What happens at Railscamp stays.......End Monday morning BrisbaneRails.com
    27. 27. RAILSCAMPs 100+ Ruby Devs BrisbaneRails.com
    28. 28. BrisbaneRails.com
    29. 29. Next RailsCamp is June, 15th BrisbaneRails.com
    30. 30. Local ActivitiesActionHack1st Saturdayhttp://www.meetup.com/BrisJelly BrisbaneRails.com
    31. 31. Work OpportunitiesRuby on Rails developers are in high demand $60K - $120+K (more overseas) $600 - $1200/day freelance Melbourne & Sydney highest demand BrisbaneRails.com
    32. 32. Perception of Ruby Community BrisbaneRails.com
    33. 33. Ruby PerceptionCult statusSacrifice goats in the search for clean code BrisbaneRails.com
    34. 34. Ruby Perception (Actual) Very supportive community Very opinionated community Very sharing (gems/code/blogs) Very quality conscious Majority devs do TDD/BDD BrisbaneRails.com
    35. 35. EnvironmentsMac InstalledWindows New installersLinux Easy BrisbaneRails.com
    36. 36. Rubies Implementations Ruby MRI REE JRuby Rubinius IronRuby MacRuby BrisbaneRails.com
    37. 37. RVMRuby Version ManagerAllows multiple implementationsAllows multiple versions of implementationsEasy swap around and gem management BrisbaneRails.com
    38. 38. ServerBEFORE fast-cgi with reverse proxiesNOW Passenger (mod rails) heroku.com BrisbaneRails.com
    39. 39. Real World Web AppsAmerican Yellow PagesTwitterHuluSlidesharegithubRedbubbleIPHONE APIS BrisbaneRails.com
    40. 40. ToolsCapistranoCucumberRspecAutoTest BrisbaneRails.com
    41. 41. GemsRubyGems is a package manager for theRuby programming language that provides astandard format for distributing Rubyprograms and libraries (in a self-containedformat called a "gem"), a tool designed toeasily manage the installation of gems, and aserver for distributing them. BrisbaneRails.com
    42. 42. BrisbaneRails.com
    43. 43. BrisbaneRails.com
    44. 44. BrisbaneRails.com
    45. 45. IRB BrisbaneRails.com
    46. 46. Ruby 101 BrisbaneRails.com
    47. 47. Interpreted Ruby No compilation Interactive Mode > ruby app.rb > irb BrisbaneRails.com
    48. 48. No Type Casting Ruby No Type declarations value = 1 puts value -> 1 value = “hello” puts value -> “hello” BrisbaneRails.com
    49. 49. Everything is an object Ruby puts 99.class -> Fixnum puts “hello”.class -> String puts nil.class -> NilClass BrisbaneRails.com
    50. 50. Skip parenthesis Ruby Most of the time Easier to read puts “hello” DSL friendly puts(“hello”) BrisbaneRails.com
    51. 51. Variables Ruby Constant Local VAR = “constant” Instance var = “local” @var = “instance” Class @@var = “class” $var = “smelly” Global BrisbaneRails.com
    52. 52. Naming Conventions Ruby underscore separated - variables and methods full_name All Caps - constants SERVER_ID CamelCase for classes ActiveRecord BrisbaneRails.com
    53. 53. Basic Data Types Ruby Numbers Strings Arrays Hashes Symbols true, false, nil BrisbaneRails.com
    54. 54. Numbers Ruby Integer Float 5 / 3 -> 1 Autoconversion 5.0 / 3 -> 1.66666.... 5 / 3.0 -> 1.66666.... BrisbaneRails.com
    55. 55. Arrays Ruby 0 indexed arrays var = [ 1, 2, 3] var[1] -> 2 var << 4 -> [ 1, 2, 3, 4] nested = [ [1, 2], 3] BrisbaneRails.com
    56. 56. Hashes Ruby Ordered named arraysvar = {:name => “Fred”, “age” => 21}puts var[:name] -> “Fred”puts var[“name”] -> nilputs var[“age”] -> 21Ruby 1.9.x{ name: “Fred”, age: 21 } BrisbaneRails.com
    57. 57. Symbols Ruby Identifier Not assignable {:password => “secret”} Mainly used in hashes :password = 42 (invalid) var = :password puts var -> :password BrisbaneRails.com
    58. 58. true, false, nil Ruby good = true bad = false unknown = nil BrisbaneRails.com
    59. 59. falsies Ruby nil and false everything else is true var = 0 0 => true if var puts “hello” “0” => true end “” => true -> “hello” BrisbaneRails.com
    60. 60. Assignment Ruby value = “hello” a = 10 a += 1 => 11 b ||= 10 => 10 b ||= 500 => 10 BrisbaneRails.com
    61. 61. Conditions Ruby If statement if name == “Fred” Unless (invert) put “Hello, Fred” end var = false if var puts “never seen” end unless var puts “always seen” end BrisbaneRails.com
    62. 62. Conditions Ruby Single line conditions var = true puts “shown” if var puts “hide” unless var puts “I win” if score > 11 BrisbaneRails.com
    63. 63. Methods Rubydef say_hello puts “hello”endsay_hello -> “hello”def my_name_is name “my name is “ + nameendputs my_name_is “Fred” -> “my name is Fred” BrisbaneRails.com
    64. 64. Classes RubyClass MyThing def initialize name @name = name end attr_accessor :name, :age def something name + “ is “ + age + “years old” endenda = MyThing.new “Fred”puts a.namea.age = 42puts a.something -> “Fred is 42 years old” BrisbaneRails.com
    65. 65. Iterator and blocks Ruby5.times do puts “Nice for-loop, eh?”end5.times { puts “One-liner block form” }(1..3).each do |n| puts “Say hello to number #{n}!”end[1,2,3].map { |n| n * 2 } -> [2, 4, 6] BrisbaneRails.com
    66. 66. Iterators Rubyitems = [“good”, “great”, “superb”] BrisbaneRails.com
    67. 67. Iterators Rubyitems = [“good”, “great”, “superb”]for item in items puts itemend BrisbaneRails.com
    68. 68. Iterators Rubyitems = [“good”, “great”, “superb”]for item in items puts itemenditems.each do |item| puts itemend BrisbaneRails.com
    69. 69. Iterators Rubyitems = [“good”, “great”, “superb”]for item in items puts itemenditems.each do |item| puts itemenditems.each { |item| puts item } BrisbaneRails.com
    70. 70. Iterator - Map Rubyitems = [“good”, “great”, “superb”]build = []items.each do |item| build << item.upcaseendbuild = items.map do |item| item.upcaseend BrisbaneRails.com
    71. 71. Iterator - select Rubyitems = [“good”, “great”, “superb”]items.select do |item| item.include? “e”end-> [“great”, “superb”] BrisbaneRails.com
    72. 72. Blocks Rubydef say_something yield yield yieldendsay_something { puts "Hello" }HelloHelloHello BrisbaneRails.com
    73. 73. Testing Rubyrequire test/unitdef my_name_is name “my name is “ + nameendclass TestIt < Test::Unit::TestCase def test_it assert_equal "my name is Fred", my_name_is “Fred" endend BrisbaneRails.com
    74. 74. Testing - RSpec Rubyrequire rspecdef greeting name “my name is “ + nameenddescribe Greeting it “should return message with name” do greeting.should == "my name is Fred” endend BrisbaneRails.com
    75. 75. Demo and Break BrisbaneRails.com
    76. 76. Ruby on Rails BrisbaneRails.com
    77. 77. Ruby on Rails BrisbaneRails.com
    78. 78. Ruby on RailsConvention over configuration BrisbaneRails.com
    79. 79. Ruby on RailsConvention over configurationDRY - Don’t Repeat Yourself BrisbaneRails.com
    80. 80. Ruby on RailsConvention over configurationDRY - Don’t Repeat YourselfMVC - Model View Controller BrisbaneRails.com
    81. 81. Ruby on RailsConvention over configurationDRY - Don’t Repeat YourselfMVC - Model View ControllerORM - Object Relation Mapping BrisbaneRails.com
    82. 82. Ruby on RailsConvention over configurationDRY - Don’t Repeat YourselfMVC - Model View ControllerORM - Object Relation MappingMigrations BrisbaneRails.com
    83. 83. Ruby on RailsConvention over configurationDRY - Don’t Repeat YourselfMVC - Model View ControllerORM - Object Relation MappingMigrationsRestful BrisbaneRails.com
    84. 84. Convention over ConfigurationConsistent StructureNaming conventions Controller names -> Model names Model names -> table names BrisbaneRails.com
    85. 85. Don’t Repeat Yourself DRYOne copy of a methodRe-usable methodspartial forms BrisbaneRails.com
    86. 86. Model View Controller MVC1979 conceptController managesactionModel connects to DBViews separated fromlogicRouter BrisbaneRails.com
    87. 87. Controller Railsclass CompaniesController < ApplicationController def index @companies = Company.all end def show @company = Company.find(params[:id]) end def new @company = Company.new end def create @company = Company.new(params[:company]) if @company.save redirect_to @company, :notice => "Successfully created company." else render :action => new end end BrisbaneRails.com
    88. 88. View - Index Rails<table> <tr> <th>Name</th> <th>Website</th> </tr> <% for company in @companies %> <tr> <td><%= company.name %></td> <td><%= company.website %></td> <td><%= link_to "Show", company %></td> <td><%= link_to "Edit", edit_company_path(company) %></td> <td><%= link_to "Destroy", company, :confirm => Are you . </tr> <% end %></table><p><%= link_to "New Company", new_company_path %></p> BrisbaneRails.com
    89. 89. View - Index .haml Rails%table %tr %th Name %th Website - for company in @companies %tr %td= company.name %td= company.website %td= link_to "Show", company %td= link_to "Edit", edit_company_path(company) %td= link_to "Destroy", company, :confirm => Are you ...%p = link_to "New Company", new_company_path BrisbaneRails.com
    90. 90. View - Form Rails<%= form_for @company do |f| %> <%= f.error_messages %> <p> <%= f.label :name %><br /> <%= f.text_field :name %> </p> <p> <%= f.label :website %><br /> <%= f.text_field :website %> </p> <p><%= f.submit %></p><% end %> BrisbaneRails.com
    91. 91. Model Railsclass Company < ActiveRecord::Base attr_accessible :name, :website has_many :contactsend BrisbaneRails.com
    92. 92. What’s ORMObject-Relational mapping is a programmingtechnique for converting data betweenincompatible type systems in databases andobject-oriented programming languagesSource: wikipedia BrisbaneRails.com
    93. 93. Quick Example #1select *from companieswhere id = 12item = Company.find(12) BrisbaneRails.com
    94. 94. Quick Example #2select *from companieswhere name = “Logical”item = Company.find_by_name(“Logical”)ORItem = Company.where(:name=>”Logical”) BrisbaneRails.com
    95. 95. Quick Example #3update companiesset name = “Logical Plus”where id = 12item=Company.find(12)item.name = “Logical Plus”item.saveORCompany.find(12).update_attributes(:name=>”LogicalPlus”) BrisbaneRails.com
    96. 96. Quick Example #4insert into companies (name, postcode)values (“Logical”, 4121)item=Company.newitem.name = “Logical”item.postcode = 4121item.saveORCompany.create(:name=>”Logical”, :postcode=>4121) BrisbaneRails.com
    97. 97. Model class Company < ActiveRecord::Base has_many :contacts has_many :invoices end class Contact < ActiveRecord::Base belongs_to :company has_many :invoices end class Invoice < ActiveRecord::Base has_many :invoice_items belongs_to :company belongs_to :contact end class InvoiceItem < ActiveRecord::Base belongs_to :invoice end BrisbaneRails.com
    98. 98. Migrationscreate and modify table and fields fromwithin code baseEasy deploymentReversible BrisbaneRails.com
    99. 99. RestfulRepresentational State TransferConcept of Resources7 Resourcesindex, show, edit, update, new, create,destroyHTTP verbs (get, put, post, delete) BrisbaneRails.com
    100. 100. Rails Routes companies_path GET /companies(.:format) :action=>"index” company_path GET /companies/:id(.:format) :action=>"show" new_company_path GET /companies/new(.:format) :action=>"new" POST /companies(.:format) :action=>"create"edit_company_path GET /companies/:id/edit(.:format) :action=>"edit" PUT /companies/:id(.:format) :action=>"update" DELETE /companies/:id(.:format) :action=>"destroy" BrisbaneRails.com
    101. 101. Preparation BrisbaneRails.com
    102. 102. Confirm Environmentruby -vgem -vrails -v BrisbaneRails.com
    103. 103. Rails Generationrails new my_app_namecd my_app_namerails generate ......rails console BrisbaneRails.com
    104. 104. Let’s go build something! BrisbaneRails.com
    105. 105. Nigel Rausch Thank you@nr99http://au.linkedin.com/in/nigelrauschnigelr@brisbanerails.com BrisbaneRails.com
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×