Presentation is loading. Please wait.

Presentation is loading. Please wait.

School of Informatics University of Edinburgh An Introduction to Ruby on Rails Ken Dawson.

Similar presentations


Presentation on theme: "School of Informatics University of Edinburgh An Introduction to Ruby on Rails Ken Dawson."— Presentation transcript:

1 School of Informatics University of Edinburgh An Introduction to Ruby on Rails Ken Dawson

2 November 2006An Introduction to Ruby on Rails 2 ● What is Ruby on Rails? ● The ruby language ● Using Ruby on Rails with DICE ● Tables, objects and URLs ● Setting up a web interface to a database ● Rails directory structure ● Simple worked example ● A real application - https://devproj.inf.ed.ac.uk/ ● References

3 November 2006An Introduction to Ruby on Rails 3 What is Ruby on Rails? ● A web application framework written in the ruby programming language ● It provides a way of quickly prototyping web applications that interface to a database and then supports the development of the application to greater levels of sophistication ● Uses the Model-view-controller architecture ● Open source software first released in July 2004

4 November 2006An Introduction to Ruby on Rails 4 The Ruby Language ● Object oriented programming language ● Claimed to allow writing of compact, readable and maintainable code ● Syntax and semantics are 'intuitive and very clean'

5 November 2006An Introduction to Ruby on Rails 5 Using Ruby on Rails with DICE To include the rails software use: #include To use mysql as the database use: #include To use apache1.3 (with kx509 authentication) use: #include

6 November 2006An Introduction to Ruby on Rails 6 Tables, Objects and URLs Rails automatically maps each URL on the web server that does not correspond to an actual file to a class and a method of that class (with any third element of the url being passed as the value of a variable :id) RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ dispatch.cgi [QSA,L] Database Table Clas s UR L cabbage s Cabbag e http:// : /cabbage/

7 November 2006An Introduction to Ruby on Rails 7 Setting up a Web Interface to a Database ● Set up the initial rails framework for your database ( in our example database name is demo ) $ rails demo ● Create the database and tables ( using say mysql ) ● Edit the rails database configuration file (demo/config/database.yml) to set database name, password and socket ● Make the public directory be the document root for the web server

8 November 2006An Introduction to Ruby on Rails 8 Rails Directory Structure 1 / public / apps / config / index.htm l dispatch.cg i database.ym l environment.r b controllers / views / models / layouts / script / generat e serve r

9 November 2006An Introduction to Ruby on Rails 9 Simple Worked Example ● Generate the rails model and controller files for the class 'Purchase' $ ruby script/generate model Purchase $ ruby script/generate controller Purchase ● Defining new class methods/actions ● Using the rails default definitions of standard actions – scaffold : $ ruby script/generate scaffold Item

10 November 2006An Introduction to Ruby on Rails 10 Rails Directory Structure 2 / public / apps / config / script / index.htm l dispatch.cg i database.ym l environment.r b controllers / views / generat e serve r models / c1 _ controller. r b c2 _ controller. r b layouts / c1 / c2 / c1. r b c2.r b

11 November 2006An Introduction to Ruby on Rails 11 Rails Directory Structure 3 / public / apps / config / index.htm l dispatch.cg i database.ym l environment.r b controllers / views / models / c1_controller.r b c1 / c2_controller.r b c2 / c1.r b c2.r b m1.rhtm l m2.rhtm l script / generat e serve r layouts / c1.r b c2.r b

12 November 2006An Introduction to Ruby on Rails 12 A Real Application The web application for tracking the progress on development projects was developed using Ruby on Rails. The web site is at https://devproj.inf.ed.ac.ukhttps://devproj.inf.ed.ac.uk It uses apache 1.3 as the web server and mysql 3.23 as the database server.

13 November 2006An Introduction to Ruby on Rails 13 References ● http://wiki.rubyonrails.org/rails http://wiki.rubyonrails.org/rails ● http://api.rubyonrails.org/ http://api.rubyonrails.org/ ● http://www.rubycentral.com/ http://www.rubycentral.com/ ● http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.htm l http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.htm l


Download ppt "School of Informatics University of Edinburgh An Introduction to Ruby on Rails Ken Dawson."

Similar presentations


Ads by Google