SlideShare a Scribd company logo
1 of 30
Rails provides the structure for disciplined web scripting, or  ,[object Object],[object Object],[object Object],Cannelloni beats spaghetti
===== Act I
There are different languages to choose for web programming Python PHP Ruby VB Java C# interpreted compiled
Picking a language to teach for web scripting can be difficult ,[object Object],Familiar and available unknown
Some scripting languages don’t encourage good habits demo/ scripts/ connect.txt functions.txt index.php list.php menu.txt <?php include(&quot;scripts/connect.txt&quot;); include(“scripts/functions.txt”); $query = &quot;SELECT * FROM auctionItems “. “ where id = '&quot; .$id .&quot;'&quot; ; $result = @mysql_query($query); include(“scripts/menu.txt”); while($row=mysql_fetch_array($result)) { echo(&quot;<p>Description: &quot;. $row[&quot;description&quot;] .“ &quot;); echo(&quot;Current Price: &quot; .$row[&quot;highBid&quot;] .&quot;</p>&quot;); ?> Spaghetti code = code from many files
Ruby on Rails provides structured web scripting travelagent/ app/ controllers/ client_controller.rb models/ show.rhtml class ClientController < ApplicationController def show  @customer = Customer.find(params[:id])  end end Cannelloni code = self contained code class Customer < ActiveRecord::Base end views/ customer.rb <% for column in Customer.content_columns %> <p><b><%= column.human_name %>: </b>  <%=h @customer.send(column.name) %> </p><% end %> client/
Learn and teach Ruby on Rails for web scripting Cannelloni beats spaghetti
=====  Act II, Scene 1
Teach how Rails implements the model-view-controller pattern Controller Model View
Controllers determine the action Controller Browser
Models handle the data Controller Database Model Browser
Views serve the presentation Controller Database Model View Browser
===== Act II, Scene 2
Teach Ruby along with Rails Ruby Rails
Teach how to create instances and classes class ClientController <  ApplicationController … def new  @customer = Customer.new end  … end
Teach to iterate through arrays ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Teach exception handling, helpers and filters ,[object Object],[object Object],[object Object]
===== Act II, Scene 3
Use a flexible and familiar example
Start with simple components ,[object Object]
Integrate object/relationship mapping for more complexity ,[object Object],[object Object],[object Object],class Customer < ActiveRecord::Base has_one :address has_many :creditcards has_many :reservations end
Provide a foundation for more elaborate examples ,[object Object]
Is there a good structure for teaching web scripting? ,[object Object]
===== Act III
Ease of scripting threatens disciplined scripting   ,[object Object]
Teach Ruby on Rails for web scripting Cannelloni beats spaghetti
Rails provides the structure for disciplined web scripting travelagent/ app/ controllers/ client_controller.rb models/ show.rhtml class ClientController < ApplicationController def show  @customer = Customer.find(params[:id])  end end Cannelloni code = self contained code class Customer < ActiveRecord::Base end views/ customer.rb <% for column in Customer.content_columns %> <p><b><%= column.human_name %>: </b>  <%=h @customer.send(column.name) %> </p><% end %> client/
Ruby on Rails: Structure for web scripting Filled cannelloni beats saucy spaghetti
Demo ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Resources: ,[object Object],[object Object],[object Object],[object Object],[object Object],The book :  Agile Web Development with Rails, 2 nd  Edition , by Dave Thomas, and David H. Hansson http://www.pragmaticprogrammer.com/titles/rails/ The site:  http://www.rubyonrails.com/ The editor:  http://www.radrails.org/

More Related Content

What's hot

Bullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-FrameworkBullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-Framework
Vance Lucas
 
DDD on example of Symfony (Webcamp Odessa 2014)
DDD on example of Symfony (Webcamp Odessa 2014)DDD on example of Symfony (Webcamp Odessa 2014)
DDD on example of Symfony (Webcamp Odessa 2014)
Oleg Zinchenko
 
Apache Camel - WJax 2008
Apache Camel - WJax 2008Apache Camel - WJax 2008
Apache Camel - WJax 2008
inovex GmbH
 
Design patterns as power of programing
Design patterns as power of programingDesign patterns as power of programing
Design patterns as power of programing
Lukas Lesniewski
 

What's hot (20)

Boston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on RailsBoston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on Rails
 
What's new in Rails 2?
What's new in Rails 2?What's new in Rails 2?
What's new in Rails 2?
 
HTML5 for Rich User Experience
HTML5 for Rich User ExperienceHTML5 for Rich User Experience
HTML5 for Rich User Experience
 
symfony & jQuery (phpDay)
symfony & jQuery (phpDay)symfony & jQuery (phpDay)
symfony & jQuery (phpDay)
 
Elegant Error-Handling for a More Civilized Age
Elegant Error-Handling for a More Civilized AgeElegant Error-Handling for a More Civilized Age
Elegant Error-Handling for a More Civilized Age
 
Changing Template Engine
Changing Template EngineChanging Template Engine
Changing Template Engine
 
Telling Stories With RSpec
Telling Stories With RSpecTelling Stories With RSpec
Telling Stories With RSpec
 
Agile Development With Hobo
Agile Development With HoboAgile Development With Hobo
Agile Development With Hobo
 
Bullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-FrameworkBullet: The Functional PHP Micro-Framework
Bullet: The Functional PHP Micro-Framework
 
DDD on example of Symfony (Webcamp Odessa 2014)
DDD on example of Symfony (Webcamp Odessa 2014)DDD on example of Symfony (Webcamp Odessa 2014)
DDD on example of Symfony (Webcamp Odessa 2014)
 
Apache Camel - WJax 2008
Apache Camel - WJax 2008Apache Camel - WJax 2008
Apache Camel - WJax 2008
 
Evolution of API With Blogging
Evolution of API With BloggingEvolution of API With Blogging
Evolution of API With Blogging
 
AngularJS with Slim PHP Micro Framework
AngularJS with Slim PHP Micro FrameworkAngularJS with Slim PHP Micro Framework
AngularJS with Slim PHP Micro Framework
 
Roman Schejbal: From Madness To Reason
Roman Schejbal: From Madness To ReasonRoman Schejbal: From Madness To Reason
Roman Schejbal: From Madness To Reason
 
Hello World on Slim Framework 3.x
Hello World on Slim Framework 3.xHello World on Slim Framework 3.x
Hello World on Slim Framework 3.x
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
 
Introduction to JQuery
Introduction to JQueryIntroduction to JQuery
Introduction to JQuery
 
Create a web-app with Cgi Appplication
Create a web-app with Cgi AppplicationCreate a web-app with Cgi Appplication
Create a web-app with Cgi Appplication
 
Design patterns as power of programing
Design patterns as power of programingDesign patterns as power of programing
Design patterns as power of programing
 
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram VaswaniCreating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
 

Viewers also liked (9)

Photo Journal (Lyle Teng) Final Draft
Photo Journal (Lyle Teng) Final DraftPhoto Journal (Lyle Teng) Final Draft
Photo Journal (Lyle Teng) Final Draft
 
Differantal
DifferantalDifferantal
Differantal
 
Tci corregido
Tci corregidoTci corregido
Tci corregido
 
Web 20 group e
Web 20 group eWeb 20 group e
Web 20 group e
 
eTV Pitch
eTV PitcheTV Pitch
eTV Pitch
 
Engro Security Analyst Briefing 1st Quarter 2011
Engro Security Analyst Briefing 1st Quarter 2011Engro Security Analyst Briefing 1st Quarter 2011
Engro Security Analyst Briefing 1st Quarter 2011
 
Metáfora
MetáforaMetáfora
Metáfora
 
ACTIVIDAD 2.
ACTIVIDAD 2.ACTIVIDAD 2.
ACTIVIDAD 2.
 
Relieve España. Definiciones e imágenes.
Relieve España. Definiciones e imágenes.Relieve España. Definiciones e imágenes.
Relieve España. Definiciones e imágenes.
 

Similar to Jicc teaching rails

Building Web Interface On Rails
Building Web Interface On RailsBuilding Web Interface On Rails
Building Web Interface On Rails
Wen-Tien Chang
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails Turtorial
Yi-Ting Cheng
 
A Web Developer's Journey across different versions of ASP.NET
A Web Developer's Journey across different versions of ASP.NETA Web Developer's Journey across different versions of ASP.NET
A Web Developer's Journey across different versions of ASP.NET
Harish Ranganathan
 
Integrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby AmfIntegrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby Amf
railsconf
 
5 Reasons To Love CodeIgniter
5 Reasons To Love CodeIgniter5 Reasons To Love CodeIgniter
5 Reasons To Love CodeIgniter
nicdev
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
funkatron
 

Similar to Jicc teaching rails (20)

Building Web Interface On Rails
Building Web Interface On RailsBuilding Web Interface On Rails
Building Web Interface On Rails
 
Rails 2.3 and Rack - NHRuby Feb 2009
Rails 2.3 and Rack - NHRuby Feb 2009Rails 2.3 and Rack - NHRuby Feb 2009
Rails 2.3 and Rack - NHRuby Feb 2009
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails Turtorial
 
A Web Developer's Journey across different versions of ASP.NET
A Web Developer's Journey across different versions of ASP.NETA Web Developer's Journey across different versions of ASP.NET
A Web Developer's Journey across different versions of ASP.NET
 
ASP.NET MVC
ASP.NET MVCASP.NET MVC
ASP.NET MVC
 
Integrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby AmfIntegrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby Amf
 
Flex With Rubyamf
Flex With RubyamfFlex With Rubyamf
Flex With Rubyamf
 
5 Reasons To Love CodeIgniter
5 Reasons To Love CodeIgniter5 Reasons To Love CodeIgniter
5 Reasons To Love CodeIgniter
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
 
EPiServer Web Parts
EPiServer Web PartsEPiServer Web Parts
EPiServer Web Parts
 
Jsp
JspJsp
Jsp
 
Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClient
 
Introduction To Ruby On Rails
Introduction To Ruby On RailsIntroduction To Ruby On Rails
Introduction To Ruby On Rails
 
Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09Even Faster Web Sites at jQuery Conference '09
Even Faster Web Sites at jQuery Conference '09
 
10 Things You're Not Doing [IBM Lotus Notes Domino Application Development]
10 Things You're Not Doing [IBM Lotus Notes Domino Application Development]10 Things You're Not Doing [IBM Lotus Notes Domino Application Development]
10 Things You're Not Doing [IBM Lotus Notes Domino Application Development]
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Developing and testing ajax components
Developing and testing ajax componentsDeveloping and testing ajax components
Developing and testing ajax components
 
Vb.Net Web Forms
Vb.Net  Web FormsVb.Net  Web Forms
Vb.Net Web Forms
 
ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introduction
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 

Jicc teaching rails

  • 1.
  • 3. There are different languages to choose for web programming Python PHP Ruby VB Java C# interpreted compiled
  • 4.
  • 5. Some scripting languages don’t encourage good habits demo/ scripts/ connect.txt functions.txt index.php list.php menu.txt <?php include(&quot;scripts/connect.txt&quot;); include(“scripts/functions.txt”); $query = &quot;SELECT * FROM auctionItems “. “ where id = '&quot; .$id .&quot;'&quot; ; $result = @mysql_query($query); include(“scripts/menu.txt”); while($row=mysql_fetch_array($result)) { echo(&quot;<p>Description: &quot;. $row[&quot;description&quot;] .“ &quot;); echo(&quot;Current Price: &quot; .$row[&quot;highBid&quot;] .&quot;</p>&quot;); ?> Spaghetti code = code from many files
  • 6. Ruby on Rails provides structured web scripting travelagent/ app/ controllers/ client_controller.rb models/ show.rhtml class ClientController < ApplicationController def show @customer = Customer.find(params[:id]) end end Cannelloni code = self contained code class Customer < ActiveRecord::Base end views/ customer.rb <% for column in Customer.content_columns %> <p><b><%= column.human_name %>: </b> <%=h @customer.send(column.name) %> </p><% end %> client/
  • 7. Learn and teach Ruby on Rails for web scripting Cannelloni beats spaghetti
  • 8. ===== Act II, Scene 1
  • 9. Teach how Rails implements the model-view-controller pattern Controller Model View
  • 10. Controllers determine the action Controller Browser
  • 11. Models handle the data Controller Database Model Browser
  • 12. Views serve the presentation Controller Database Model View Browser
  • 13. ===== Act II, Scene 2
  • 14. Teach Ruby along with Rails Ruby Rails
  • 15. Teach how to create instances and classes class ClientController < ApplicationController … def new @customer = Customer.new end … end
  • 16.
  • 17.
  • 18. ===== Act II, Scene 3
  • 19. Use a flexible and familiar example
  • 20.
  • 21.
  • 22.
  • 23.
  • 25.
  • 26. Teach Ruby on Rails for web scripting Cannelloni beats spaghetti
  • 27. Rails provides the structure for disciplined web scripting travelagent/ app/ controllers/ client_controller.rb models/ show.rhtml class ClientController < ApplicationController def show @customer = Customer.find(params[:id]) end end Cannelloni code = self contained code class Customer < ActiveRecord::Base end views/ customer.rb <% for column in Customer.content_columns %> <p><b><%= column.human_name %>: </b> <%=h @customer.send(column.name) %> </p><% end %> client/
  • 28. Ruby on Rails: Structure for web scripting Filled cannelloni beats saucy spaghetti
  • 29.
  • 30.

Editor's Notes

  1. Hello, sorry for the food analogy just before lunch, but as you’ll see, it’s appropriate. I shall run through the presentation and then do a short demo at the end showing you how to set up a simple Ruby on Rails web site. I’m not trying to show you how to build a Ruby on Rails site, by the way, but rather convince you of its value as tool for teaching web scripting.
  2. When we started teaching Web Design and Administration at the University of Aberdeen we choose to use PHP. We excluded compiled languages as they are covered elsewhere in the degree. We didn’t have to choose PHP. We could have also looked at Python, or Ruby. However, admittedly at this time neither were really on the radar for web site building. Ideally we should’ve worked out a list of qualities that we desired in the language we were going to use. However, we didn’t have the time for this, and we already knew that we would use PHP.
  3. PHP was the scripting language familiar to the course team, and the department web servers were already set up to handle PHP. It was an easy choice for us when we started the course.
  4. PHP is easy to use. You create a variable and manipulate it. You can connect to a database and display the results on the page without any problem. In order to use it well you need to create libraries of code, or at the very least break up the code into small scripts of functions that are reused where appropriate so that you can change the database access details in only one place when you move the database. Students don’t seem to remember this no matter how many times they run through the practical on this in a lab, or read the lecture notes. It probably has something to do with the fact that a number of them have already learned PHP by the time you see them too, which means that they think they know it all, and don’t pay as much attention as they should. The result is that no matter that you start with nice clean files of code, by the time assessments are handed it, the straight coding has been turned like spaghetti from solid straight pieces to a tangle of spaghetti code.
  5. Ruby on Rails is the antitheses of a PHP application. In a Ruby on Rails application every part of the code has a specific place where it should be. Code that affects the business logic of the application goes into the controller classes. Code dealing with the instance data goes into the model, while code affecting the look and feel of the site belongs in the view files. This structured approach means that the developer should know where the code belongs. In a PHP application you can put the code where you want to, and it can develop into a spaghetti bowl full of tangled code. In a Rails application this will be a structured bowl of cannelloni, all nicely laid out in rows.
  6. If you learn Ruby on Rails and teach it to your students, then you get a number of benefits. Instead of bored students, who ‘know it all about PHP’, you’ll have interested students wanting to learn a new language and framework. Instead of spaghetti code you get cannelloni code, which makes for better coding habits. Instead of learning how to script variables to build an application, the students have another example, as with Java, of using objects to build applications. Making the switch to using Ruby on Rails instead of PHP, or another scripting language is straightforward as you’ll see.
  7. The first part of teaching students about Ruby on Rails is that everything happens within the model-view-controller design pattern. The students need to understand how the pattern is implemented in Rails so that they can work with the structure. In our department at Aberdeen University this is usually the students’ first encounter with design patterns. Although the students are also taking the software engineering course at the same time, they don’t start design patterns in that course until the following week. In any case, this overlapping will aid the students in understanding what patterns are and how they are applied in a Rails application.
  8. Controllers in a Ruby on Rails application intercept the page requests from the browser and then marshal the details for a response. This could mean using a model to query the database, or using a model to validate a user login. Whatever. In any case, once the controller has the result, it then pushes the result to the appropriate view. Usually there is more than one controller for an application. It is common to have one controller for each model, and then others to coordinate the action between the other controllers for a smooth running application.
  9. Models hold the instance details for the application. They are the objects that are manipulated by the controllers in the application. They represent users, customers, products, books, etc. If a new instance is created then the model determines what needs to be validated before the object is created.
  10. When a controller has the result of the page requested by the browser, then it hands this to the appropriate view file. This file knows how to present the response to the browser. In a Rails application these are built up from a small collection of templates to speed development, which also make it easy to integrate shared menus so that code is not needlessly repeated.
  11. Ruby underpins the Rails framework so the students need to learn this too. In addition to learning how Rails implements the model-view-controller pattern, they need to learn basic Ruby language structures so that they can write methods, as well as understand the Rails generated code, and modify it as required.
  12. In the first practical the students create a basic site with some simple controllers and methods tied to hand crafted views. This is by way of showing them how the Rails structure works and which files are required to handle a page request and a response. We do this with a simple hello and goodbye example using one controller and two views. We put two methods in the controller, one for each view, and then modify the views with some basic scripting. Later we start a larger example that they’ll use over several weeks, which brings models into the exercise so that they see how controllers deal with models.
  13. Arrays are everything in a Rails application. When a controller queries a model to obtain a list of products, for example, then this is returned as an array. When the same array is displayed on the web page in the view, then this is iterated over by the page. Similarly, if the controller method wanted to find a specific product in the array, then this too means searching through the array. Arrays are easy to do in Ruby, and there are various ways to work with them. Rails also adds its own ways. The students need to learn a few of them so that they can get the most out of their Rails applications. As here, too, we can retrieve arrays of models associated with other objects and iterate through them.
  14. The students also need to know how to handle exceptions for when things go wrong. They need to tell the application what to do when something is ‘nil’ instead of a value, or when it’s not the expected value. They also need to be able to write helpers, bits of code that can be called by different views, without having to write it as a file include. Helpers apply to contollers and allow you, for example, to call formatting code for prices in different currencies. Filters are also useful as they represent chunks of code that can be called before or after another method. For example, if some methods can only be run by authorised users, then we can have the authorisation method called first before any of these other methods are run. We can also use this for logging if we want run ‘around’ filters that place the method within the filter so that, for example, we could time a method.
  15. Throughout the practicals the students work with a cruise booking example. This provides cruises on ships, and cabins booked for cruises, which are reserved by customers, who pay with them using one of their credit cards. At one level this is a simple example, while on another there is lots of scope for further work.
  16. The first practical has the students set up basic models and controllers for the different tables of customers, addresses, credit cards, ships, cruises, reservations and payments. This gets them used to the basic structure that Rails creates and they can see how easy it is to manipulate the basic application.
  17. The next step is to integrate the object relationship mapping to deal with one-to-one and one-to-many as well as many-to-many relationships. This is one place where the real power of Ruby and Rails shows up, because it is not that difficult to set up. We only need to add some lines of code to the model objects and that’s it. Rails does the rest.
  18. Beyond the relationships of the objects we can also move on to explore other parts of the application as time and student aptitude allow. We could change some of the methods so that they use AJAX, or we could integrate RSS feeds into the application to show new cruises as they are added. In addition, there is the rest of the workflow for the application because at the moment it only has some parts tied together.
  19. So, we’re back where we started. Looking for a good structure for teaching web scripting. I’ve tried to show how Ruby on Rails makes this easier.
  20. As noted earlier PHP has problems with resembling spaghetti instead of cannelloni if good habits aren’t followed. In addition there is the problem that some students think they know it all when it comes to PHP because they’ve been using it for a number of years already. This means that they skip practicals, don’t pay much attention in class, and then don’t improve their habits, and their attitude potentially influences other students in the class too.
  21. Teaching Ruby on Rails for web scripting has a number of benefits. Its model-view-controller structure forces students to understand the pattern, which they should be able to ‘port’ to other applications, when they encounter it in Java, or whatever. The students learn to work with components instead of only variables, which is what tends to happen with PHP. Ruby like other scripting languages is easy to learn and its brevity make it fun to use.
  22. The predetermined layout and model-view-controller component structure of a Rails application make it simple to know where parts of code should be placed in an application. Each of the models, controllers and views has an appropriate role to play in the application, and this structure, once the students understand it, makes it simple to know where code belongs so that it is not repeated.
  23. Useful starting points for learning Ruby on Rails programming: The book: http://www.pragmaticprogrammer.com/titles/rails/index.html The site: http://www.rubyonrails.com/ The editor: http://www.radrails.org/