1 / 18

Creating Web Services with Ruby on Rails

Creating Web Services with Ruby on Rails. Robert Thew Internet and Web Systems II. What is Ruby?. Ruby is a language created in Japan in 1995 by Yukihiro Matsumoto It ’ s an Object-Oriented language that also has elements of Functional languages. Why Create Ruby?.

eris
Download Presentation

Creating Web Services with Ruby on Rails

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Creating Web Services with Ruby on Rails Robert Thew Internet and Web Systems II

  2. What is Ruby? • Ruby is a language created in Japan in 1995 by Yukihiro Matsumoto • It’s an Object-Oriented language that also has elements of Functional languages

  3. Why Create Ruby? • Matsumoto wanted to create a language that combined all his favorite features into one language

  4. What Are Ruby’s Features? • Completely Object-Oriented • Can do Functional as well as Imperative programming • Clean, simple and consistent syntax

  5. Basics of Ruby • Demo using irb

  6. Ruby on Rails • A Model-View-Controller Web Framework for Ruby developed in 2004 by David Heinemeier Hansson • Guiding principle is Convention over Configuration • Very little boilerplate code • Small classes with short methods • Allows for rapid development

  7. Installation • Ruby and RoR come installed on MacPros • Can be downloaded and installed from: • ruby-lang.org • rubyonrails.org • MySQL can be downloaded from mysql.com

  8. Building an Application • Run the rails command to create a new application framework • Go into the new directory and edit the database config file • Add user and password for development entry $rails new biblio $cd biblio $vi config/database.yml

  9. Create Database • Create an empty development database instance $rake db:create

  10. What Is Rake? • Rake is Ruby’s version of Make • Rakefiles use ruby syntax – so no whitespace problems • Rails applications come with rakefiles for running database commands and for doing unit tests

  11. Test Application • Rails uses WEBrick, a ruby library that provides a basic HTTP server >rails s => Booting WEBrick => Rails 3.0.5 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server

  12. Generate MVC Files • Rails comes with a generator that will create database migrations, model, view, controller, and test files >rails generate scaffold Article title:stringauthor:stringurl:stringabstract:text

  13. Database Migration • Migration classes are used to create and modify tables >rake db:migrate

  14. Model and Controller Code • Note how short all the methods are • Convention over Configuration means code can be kept simple • No need for explicit getters and setters in the Model

  15. RESTful Architecture • All the URLs will follow the same pattern for CRUD (Create Read Update Delete)operations • REST (Representational State Transfer) is a simpler and consistent alternative to SOAP

  16. URL Patterns These URLs are routed to their respective controller methods. GET /articles GET /articles/new POST /articles GET /articles/1 GET /articles/1.xml GET /articles/1/edit PUT /articles/1 DELETE /articles/1

  17. Test Application >rails s >rails c

  18. Rails Tools • Git – Distributed versioning system • Capistrano – For scripting deployments • RubyGems – Package dependency manager • RVM – Run multiple versions on one system • Heroku – Ruby Cloud Platform as a Service

More Related