Click here to load reader

Ruby on Rails - Jose M. · PDF fileRuby: The Foundation Rails: The Framework Conclusion Ruby on Rails An Overview J. Dew Department of Computer Science and Engineering University of

  • View
    232

  • Download
    1

Embed Size (px)

Text of Ruby on Rails - Jose M. · PDF fileRuby: The Foundation Rails: The Framework Conclusion Ruby...

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Ruby on RailsAn Overview

    J. Dew

    Department of Computer Science and EngineeringUniversity of South Carolina

    April 11, 2007

    J. Dew Ruby on Rails

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Language BasicsCompletely Object OrientedMethods, Classes and Modules

    Outline

    1 Ruby: The FoundationLanguage BasicsCompletely Object OrientedMethods, Classes and Modules

    2 Rails: The FrameworkModel-View-Controller ArchitectureDatabase-centric ProgrammingConvention over Configuration

    3 Conclusion

    J. Dew Ruby on Rails

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Language BasicsCompletely Object OrientedMethods, Classes and Modules

    Ths Basics

    Ruby is . . .A dynamic, open source programming language with a focuson simplicity and productivity. It has an elegant syntax that isnatural to read and easy to write.

    http://ruby-lang.org/

    Examplesputs "Hello World"

    name = getsputs "Hello #{name}"

    hash = {:id => 42}hash.has_key? :id

    J. Dew Ruby on Rails

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Language BasicsCompletely Object OrientedMethods, Classes and Modules

    Ths Basics

    Ruby is . . .A dynamic, open source programming language with a focuson simplicity and productivity. It has an elegant syntax that isnatural to read and easy to write.

    http://ruby-lang.org/

    Examplesputs "Hello World"

    name = getsputs "Hello #{name}"

    hash = {:id => 42}hash.has_key? :id

    J. Dew Ruby on Rails

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Language BasicsCompletely Object OrientedMethods, Classes and Modules

    Ths Basics

    Ruby is . . .A dynamic, open source programming language with a focuson simplicity and productivity. It has an elegant syntax that isnatural to read and easy to write.

    http://ruby-lang.org/

    Examplesputs "Hello World"

    name = getsputs "Hello #{name}"

    hash = {:id => 42}hash.has_key? :id

    J. Dew Ruby on Rails

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Language BasicsCompletely Object OrientedMethods, Classes and Modules

    Ths Basics

    Ruby is . . .A dynamic, open source programming language with a focuson simplicity and productivity. It has an elegant syntax that isnatural to read and easy to write.

    http://ruby-lang.org/

    Examplesputs "Hello World"

    name = getsputs "Hello #{name}"

    hash = {:id => 42}hash.has_key? :id

    J. Dew Ruby on Rails

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Language BasicsCompletely Object OrientedMethods, Classes and Modules

    Conditionals and Looping

    Examples

    3.downto(0) do |count|unless count == 0 then

    print "#{count}.."else

    puts "Blastoff!"end

    end

    J. Dew Ruby on Rails

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Language BasicsCompletely Object OrientedMethods, Classes and Modules

    Conditionals and Looping

    Examples

    3.downto(0) do |count|unless count == 0 then

    print "#{count}.."else

    puts "Blastoff!"end

    end

    Produces 3..2..1..Blastoff!

    J. Dew Ruby on Rails

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Language BasicsCompletely Object OrientedMethods, Classes and Modules

    Outline

    1 Ruby: The FoundationLanguage BasicsCompletely Object OrientedMethods, Classes and Modules

    2 Rails: The FrameworkModel-View-Controller ArchitectureDatabase-centric ProgrammingConvention over Configuration

    3 Conclusion

    J. Dew Ruby on Rails

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Language BasicsCompletely Object OrientedMethods, Classes and Modules

    Everythings an Object

    Examples42.methods.sort

    returns

    ["%", "&", "*", "**", "+", "+@", "-", "-@","/", "", "[]", "^", "__id__","__send__", "abs", "between?", "ceil", "chr","class", "clone", "coerce", "display", "div","divmod", "downto", "dup", "eql?", "equal?",..."type", "untaint", "upto", "zero?", "|", "~"]

    J. Dew Ruby on Rails

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Language BasicsCompletely Object OrientedMethods, Classes and Modules

    Outline

    1 Ruby: The FoundationLanguage BasicsCompletely Object OrientedMethods, Classes and Modules

    2 Rails: The FrameworkModel-View-Controller ArchitectureDatabase-centric ProgrammingConvention over Configuration

    3 Conclusion

    J. Dew Ruby on Rails

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Language BasicsCompletely Object OrientedMethods, Classes and Modules

    Methods

    Exampledef factorial(n)n == 1 ? 1 : n * factorial(n-1)

    end

    J. Dew Ruby on Rails

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Language BasicsCompletely Object OrientedMethods, Classes and Modules

    Classes

    Exampleclass Client

    def Client.most_lucrative(clients)# class method

    end

    def paid_in_full!# instance method

    end

    end

    J. Dew Ruby on Rails

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Language BasicsCompletely Object OrientedMethods, Classes and Modules

    Modules

    Example from Railsmodule ActiveRecord

    class Base

    def save# create or update a record

    end

    end

    end

    J. Dew Ruby on Rails

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Model-View-Controller ArchitectureDatabase-centric ProgrammingConvention over Configuration

    Outline

    1 Ruby: The FoundationLanguage BasicsCompletely Object OrientedMethods, Classes and Modules

    2 Rails: The FrameworkModel-View-Controller ArchitectureDatabase-centric ProgrammingConvention over Configuration

    3 Conclusion

    J. Dew Ruby on Rails

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Model-View-Controller ArchitectureDatabase-centric ProgrammingConvention over Configuration

    The Model

    ConceptInteracts directly with the RDBMSMaintains the state of the applicationEnforces any rules or validations related to the dataEncapsulated by ActiveRecord in Rails

    J. Dew Ruby on Rails

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Model-View-Controller ArchitectureDatabase-centric ProgrammingConvention over Configuration

    The Model

    ConceptInteracts directly with the RDBMSMaintains the state of the applicationEnforces any rules or validations related to the dataEncapsulated by ActiveRecord in Rails

    J. Dew Ruby on Rails

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Model-View-Controller ArchitectureDatabase-centric ProgrammingConvention over Configuration

    The Model

    ConceptInteracts directly with the RDBMSMaintains the state of the applicationEnforces any rules or validations related to the dataEncapsulated by ActiveRecord in Rails

    J. Dew Ruby on Rails

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Model-View-Controller ArchitectureDatabase-centric ProgrammingConvention over Configuration

    The Model

    ConceptInteracts directly with the RDBMSMaintains the state of the applicationEnforces any rules or validations related to the dataEncapsulated by ActiveRecord in Rails

    J. Dew Ruby on Rails

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Model-View-Controller ArchitectureDatabase-centric ProgrammingConvention over Configuration

    The View

    ConceptResponsible for generating the UIWhere the HTML, JS, CSS, etc residesMostly printing variables and simple loopsActionView in Rails

    J. Dew Ruby on Rails

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Model-View-Controller ArchitectureDatabase-centric ProgrammingConvention over Configuration

    The View

    ConceptResponsible for generating the UIWhere the HTML, JS, CSS, etc residesMostly printing variables and simple loopsActionView in Rails

    J. Dew Ruby on Rails

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Model-View-Controller ArchitectureDatabase-centric ProgrammingConvention over Configuration

    The View

    ConceptResponsible for generating the UIWhere the HTML, JS, CSS, etc residesMostly printing variables and simple loopsActionView in Rails

    J. Dew Ruby on Rails

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Model-View-Controller ArchitectureDatabase-centric ProgrammingConvention over Configuration

    The View

    ConceptResponsible for generating the UIWhere the HTML, JS, CSS, etc residesMostly printing variables and simple loopsActionView in Rails

    J. Dew Ruby on Rails

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Model-View-Controller ArchitectureDatabase-centric ProgrammingConvention over Configuration

    The Controller

    ConceptCoordinates between the model(s) and the view(s)Responds to user input and routes accordinglyMost of the application logic goes hereActionController in the Rails framework

    J. Dew Ruby on Rails

  • Ruby: The FoundationRails: The Framework

    Conclusion

    Model-View-Controller ArchitectureDatabase-centric ProgrammingConvention over Configuration

    The Controller

    ConceptCoordinates between the model(s) and the view(s)Responds to user input and routes accordinglyMost of the application logic goes hereActionController in the Rails framework

    J. Dew Ruby on Rails

  • Ruby: The FoundationRail

Search related