Workshop 8 – Ruby on Rails Workshop report and evaluation

Topic objectives:

 Upon the completion of this workshop, developers or managers should be able to:

  • Identify and evaluate the Ruby on Rails workshop series
  • Think critically and analytically about what you knew before and after the experiences
  • Share and post your Report and Evaluation with peers via the subject forum. 

Evaluation and Report:

Please answer each question in this evaluation section. In your answer, please consider content/topics presented and the technologies and teaching strategies used during the Ruby on Rails Workshops. Results will be collated and used to modify the workshop series.

This form is just a format guide to you evaluation and report. Thank you for your time to complete workshop 8.

  1. List what you consider to be the three strengths of Ruby on Rails workshop series
    1. The practical application of concepts such as MVC, CoC and DRY
    2. The Learning Rails podcasts are excellent
    3. Exposure to Open Source software after a career using IBM and Microsoft!
  2. List what you consider to be the three weaknesses of Ruby on Rails workshop series
    1. The amount of time required to satisfactorily complete the workshop exercises was too small.  There is a lot of new software, e.g. Instant Rails and Aptana Studio that we are required to download and get our heads around in a short period of time.
    2. There is too much time spent searching for answers.  While there is a vast amount of information available it takes time to sift through and digest.   
    3. The group interaction failed to materialise.  The tools were provided and encouragement given but the reality is we did not utilise this opportunity.
  3. List what aspects of Ruby on Rails workshop series that you found to be most difficult
    1. Adjusting my mindset after many years of mainframe programming.
    2. Installing then invoking the software was a frustrating experience due to the number of options available.
    3. Explicitly following the workshop steps often led to errors as syntax has changed with versions or worse the instructions were plain wrong.  Much time was lost due to broken links, typos and plain errors.
  4. List what improvements could be made to the Ruby on Rails workshop series
    1. Clean up all the errors in the workshop text!
    2. Improve the delivery of the software – provide up to date instructions
    3. Provide the text book
  5. Reflect on your experiences with the other Web framework used in this subject: Was it effective? How can it be improved? Should other Web frameworks be used as well or instead of Ruby on Rails?
    1. ?
  6. Did the Developer’s or IT managers Team that you joined after workshop 4 have a preference towards using other tools to facilitate collaboration? Comment on the differences between these use of the sub-forum or Interact wiki tools from your experiences in this subject.
    1. There was no collaboration at all
  7. Further comments to add?
    1. If I did not have access to other students’, both past and present, ePortfolios I would have really struggled with these workshops.  I am indebted to their help and would have spent even more time determining and rectifying errors with my code if they had not already encountered and solved the issues.
    2. One of my motivations for doing a Masters after many years of work as a mainframe programmer was to discover what had been going on in IT during that time and to see where things are headed.  This unit, and the hands on nature of these workshops in particular, is exactly what I was looking for.  I must admit that I feel some regret that I did not have more time to invest in these workshops.  

Workshop 7 – Production site migration and maintenance

Topic objectives:

Upon the completion of this workshop, developers or managers should be able to:

  • Discuss and choose the Rails production deployment configuration;
  • Identify and evaluate the ways to take move the development site on your computer to the online production site;
  • Evaluate and devise how to integrate a new Rails site into an existing or future e-commerce structure;
  • Conclude the development of the OTBS as a Ruby on Rails application;
  • Think critically and analytically about the policy for site maintenance and further development.
  • Share your findings with your peers and examine what the other team is doing.

 

Focus Question:

 As either a developer or as an IT manager, what are the options available when deploying and maintaining the Ruby on Rails application online?

 

To Do:

DEVELOPERS THREAD (RED team)

Developers conclude their work with the OTBS and look at the options for deployment of the site. Examine the various platforms/software tools used for deployment such as UNIX environment suggested in the Discussion Notes, Mongrel or Mongrel cluster, Nginx, Subversion or Capistrano (during development stage), JRuby in the Java environment. 

Which way? 

The choice is up to you as this workshop present just one option and you may like to use another, such as deploying the OTBS in a .NET or J2EE environment

Can you get the OTBS Running in production mode as a minimal production server?

Share your success by posting progress comments and links etc to the Developers sub-forum site that has been set up for the Red team.

  • Deploying Ruby on Rails is easy suggests the following tools to launch:
    • Passenger aka mod_rails – The preferred deployment setup for Rails is Phusion Passenger aka mod_rails. It’s a module for Apache that automatically manages the back end. Just setup, launch, and enjoy
    • Proxy setups – Prior to Passenger, Rails was mostly deployed using Apache or nginx with either a built-in or standalone proxy (like HAProxy) against a cluster of Mongrels or Thins. This setup is still works great, but it’s more complicated to setup and administrate than using Passenger.
    • JRuby on Rails JRuby brings Rails to the Java Virtual Machine. This means that you can deploy Rails applications on app servers like Glassfish or Jetty. You can use Warbler to package your Rails application as a standard WAR. Great for slipping into the enterprise.
    • Automate with CapistranoCapistrano brings deployment automation to Rails whether you’re working with a single server or on a cluster of dozens. It was extracted from the 37signals tool chain (like Rails) by core alumni Jamis Buck.
  • The workshop text also describes:
    • Jumpbox Ubuntu Linux environment
    • IronRuby under .NET

Notes:

  1. Passenger – it may be the preferred deployment setup for Rails but not supported by Windows.
  2. Proxy setups – an apache web server is configured to act as a proxy for any requests that are sent to the web server which then passess those requests through to the mongrel web server.  More complex than Passenger.
  3. Capistrano – for deployment to a Unix-based system such as Linux, Solaris, or Mac OS X.  A Windows deployment is problematic.

Workshop 6 – Enjoying the Ride : Web framework alternatives, scalability and flexibility

Topic Objectives:

Upon the completion of this workshop, developers or managers should be able to:

  • Discuss and analyse the latest Web framework technologies based upon experiences so far with Ruby on Rails
  • Identify and evaluate challenges and opportunities concerning the use of the latest Web 2.0 technologies and to ‘benchmark’ (compare) other alternatives;
  • Discuss and evaluate current Ruby on Rails framework and the alternative emerging technologies.
  • Evaluate and devise scalability, flexibility, capacity planning and performance testing strategies for conducting e-commerce.
  • Deploy Web 2.0 or later technology in their business environments such as the ideas and methods of the ‘RailsSpace’ approach to the OTBS
  • Think critically and analytically when exposed to new technologies.
  • Share your findings with your peers and examine what the other team is doing.

 

To Do:

DEVELOPERS THREAD (RED team)

Developers may continue to build upon work with the OTBS using the topic reading to help with user registration and advanced login features from Hartl et al (2008). Some examples of work to do includes:

  • generating a controller and an action by adding a method(s) to a controller;
  • creating a view template for each action and to link to actions from views;
  • using AJAX to improve the user experience;

Share your success by posting progress comments and links etc to the Developers sub-forum site that has been set up for the Red team.

Well this workshop has beaten me – I left it for too long and now I do not have time to do it justice (given that my forays into Ruby on Rails seem to take me 4 times as long as suggested!).  Mea culpa  (or ‘my bad’ as some might say now) – I really should have taken this unit on its own and not try to do two in the trimester (a strategy that had worked up until now).   I have also not been able to access the RailSpace textbook via Safari though have been listening to the Learning Rails podcasts.  Unfortunately this workshop required timely interaction with my peers and that just hasn’t happened.  What I have done is view the blogs of current and past students to try to glean an understanding of what may be achieved. It seems that, while some past students have struggled like me, many others have succeeded remarkably (see Karen and Alex).  Simon Russell’s blog links to the following tutorial for creating a basic user login system in RoR – (thanks Simon!).  Here is the methodology explained there – too bad I struggled implementing it:

1.  create a users table (e.g. id, name, password, role) and insert some records

2.  generate the user model:

  • C:\Users\db\InstantRails-2.0-win\rails_apps\taxi> ruby script/generate model user — skip migration          
    • this creates the file C:\Users\db\InstantRails-2.0-win\rails_apps\taxi\app\models\user.rb

3.  generate the user controller:

  • C:\Users\db\InstantRails-2.0-win\rails_apps\taxi> ruby script/generate controller user login private 
    • this creates the user controller file C:\Users\db\InstantRails-2.0-win\rails_apps\taxi\app\controllers\user_controller.rb
      • with two empty functions login and private
    • and the user view folder C:\Users\db\InstantRails-2.0-win\rails_apps\taxi\app\views\user
      • and the two html forms within the user view folder:
        • login.html.erb
        • private.html.erb

4.  edit the views:

  • edit the login form C:\Users\db\InstantRails-2.0-win\rails_apps\taxi\app\views\user\login.html.erb
    • receives a user name and password and executes an authenticate method when the submit button is presssed
  • edit the private form C:\Users\db\InstantRails-2.0-win\rails_apps\taxi\app\views\user\private.html.erb
    • displays a hello message and has a link that when clicked executes the logout method of the user controller

5.  edit the user controller:

  • edit the file C:\Users\db\InstantRails-2.0-win\rails_apps\taxi\app\controllers\user_controller.rb
    • create an authenticate method which uses an object of user to searches the db based upon the fields entered on the login form and redirects if exists to private and sets the session else back to login
    • create a logout method which resets the session and redirects to login
    • modify the private method to redirect to the login form if the session has not been set 

Simple (well you would think so!)

 

Focus Question:

The focus question below provides a way to shape your progress in either team as a common approach to achieving an outcome with the objectives. You get to shape the direction you take in these final workshops, but the focus question helps you get started.social networking sites which he applied to the OTBS took into consideration things like:

Social networking is a powerful business model made possible by Web 2.0 technologies.

The online textbook called RailsSpace has this focus.

As either a developer or as an IT manager, how can aspects of social networking be applied to the OTBS?

As I couldn’t get my OTBS up and running, nor read the RailsSpace text, I will have to leave this to Alex Ramsey who listed the following aspects: 

  • Saving Sessions,
  • Adding Cookies,
  • Saving registration details
  • Logging in registered users and
  • Updating registration Details

Workshop 5 – Admiring the scenery : Forms, AJAX screen layout and mobile interfaces

Topic objectives:

  • To reflect on what has been done so far with Ruby on Rails;
  • To reflect on my role and decide to continue as EITHER a Developer OR as an IT infrastructure manager;
  • To complete either the Developer’s Thread exercises or the IT Infrastructure manager’s Thread exercises below, according to my new role (NOT BOTH).
  • To work with others in the same role via the subject forum or similar learning tool.
  • To read and find out what those who chose the other role are doing each of the workshops 5 to 8 and discussing on the subject forum or learning tool.
  •  To be willing to change roles and share perspectives as developers learn from managers and vice versa.

DEVELOPERS THREAD (RED team)

  • To create a Rails application framework with the WEBbrick or Mongrel Web server and:
    • generate a controller and an action by adding a method(s) to a controller;
    • create a view template for each action and to link to actions from views;
    • use Rails for building applications with document requests, screen layouts and forms processing. 

To share your findings with others.

 To do:

Part A: Viewing the action

1. Create the Rails application framework in the projects folder: C:\InstantRails\…\projects\>rails animals

Created projects folder and ran >rails animals to create the rails application there.

2. Running  the application on localhost:3000 using the WeBrick ruby server (or Mongrel as alternative) and access via Web browser at http://localhost:3000/

3. Create the controller to make the application do an action. This is under the controller-action/model-view structure.

 Stop the WEBrick server each time you edit Ruby classes and then re-start or refresh the views you are testing. Use the Ruby command below:

>ruby script/generate controller Mammal

The mammal_controller.rb contains just a bare class description:

class MammalController< ApplicationController

end

and the ApplicationController class inherits from ActionController::Base class in the ActionController module under Rails.

4. Test the controller by starting the WEBrick server and navaigating the browser to http://localhost:3000/mammal Note how the controller name is appended to the end of the URL and that no action resulted because there are no controller methods.

5. Create an action by editing and saving the mammal_controller.rb class in projects\animals\app\controllers using your text editor to add the method below:

class MammalController< ApplicationController

   def breathe

   end

end

Done.

6. Start the WEBrick server and browse at http://localhost:3000/mammals/breathe where you will get a “missing template” message since it is missing a view for the breathe method.

Rails is trying to connect the breathe method action of the mammal controller to a view, by using the action’s name – breathe. This view template is created as breathe.rhtml and stored in the \projects\animals\app\views\mammal directory.

7. Create and save a view in that directory by using a text editor to create a view called breathe.rhtml

<html>

     <head>

        <title>Breathe Easy</title>

     </head>

     <body>Inhale and Exhale

     </body>

</html>

 Restart the WEBrick server and browse again at http://localhost:3000/mammals/breathe

Didn’t work as the above is incorrect – must change the url from mammals to mammal and rename the html file for Rails 2.0 to breath.html.erb

8. Try Ruby code and HTML in the action view by using the <%….%> wrapper around the inserted Ruby code. Here are some snippets to try from workshop 4:

<br>

5 + 6 =<%= 5 + 6 %> 

</br>

<br>

=<% 4.times do %> 

Inhale Exhale <br> 

<%end%>

<br>

Time is <%=Time.now %> 

</br>

 NOTE: in practise you normally perform calculations in the action (method) and pass the results to the view

 

 

 

Part B : The active view: passing data from an action to a view

 

1. Create a new application called scenery in the same projects directory to demonstrate the use of an active view.

> rails scenery

> cd scenery

Done.

2. Create a controller called Demo in scenery\app\controllers

scenery> ruby script/generate controller Demo

Done.

3. Add an action to demo_controller.rb as the method called rubycobe

class DemoController< ApplicationController

   def rubycode

   end

end

Done.

4. Add a view template – scenery\app\views\demo\rubycode.rhtml

We will edit this view in later steps but you may like to add your own test HTML code to the view at this stage.

 Done rubycode.html.erb

5. Save and restart the Web server and navigate to http://localhost:3000/scenery/rubycode

Hmm getting a routing error…should by /demo/rubycode!

6. Use the Time.now example to pass data from an action to a view.

7. Modify and save the rubycode action with a value for the time instance variable in the DemoController class in app\controllers\demo_controller.rb

class DemoController< ApplicationController

   def rubycode

      @time_now = Time.now

   end

end

Done.

8. Then modify and save the corresponding view template in \app\views\demo\rubycode.rhtml by adding a call by reference to the action’s instance variable:

<br>

The time is <%= @time.now %>

<br>

@time.now should be @time_now

9. Restart the Web server and navigate the browser to http://localhost:3000/demo/rubycode

Data has been passed from the action to the view as it is done with SQL requests. The instance variables of a Ruby class are available to view templates by referencing the action’s instance variables by name in the view .rhtml template.

Part C: Screen layouts and forms processing with text fields, check boxes, radio buttons and multiple list controls

 1. Create a new application called cabs in the same projects directory to demonstrate the use of an active view.

> rails cabs

> cd cabs

Done.

2. Create a controller called Vehicle in cabs\app\controllers

 cabs> ruby script/generate controller Vehicle

Done.

3. Add an action to vehicle_controller.rb as the method called cabtype

class VehicleController< ApplicationController

   def cabtype

   end

end

Done.

4. Add a view template – cabs\app\views\vehicle\cabtype.rhtml

We will edit this view in later steps but you may like to add your own test HTML code to the view at this stage.

Done.

5. Save the view and restart the Web server and navigate to http://localhost:3000/cabs/cabtype

Should be /vehicle/cabtype!

6. Create a file in the public directory – \cabs\public called input.html

Please note that the following includes fixes identified on other blogs!

 

7. Edit the vehicle_controller.rb here is a start. The data in each form element in the Rails application can be accessed via its name and a hash called params

class VehicleController< ApplicationController

   def cabtype

     @data1 = params[:text1]

     @data2 = params[:check1]

     @data3 = params[:radios1]

     @data4 = params[:building1]

   end

end

8. Edit the view template cabtype.rhtml

9. Start the Web server and go to the opening page of this application at http://localhost:3000/input.html

10. Submit the forms data. What do you find?

I can’t get it to work despite all the felp from other blogs!

11. Report your progress or findings in your Developers Blog

This whole section needs fixing to remove all the frustrating errors – will that taxi ever arrive?

Workshop 4 – Riding the Rails with Ruby

Topic objectives:

  • To learn about the Ruby language and its classes and methods
  • To use Ruby via an interpreter console window with Windows, Linux or MacOS
  • To select and test a Ruby IDE
  • To explain how Rails framework is built upon inheritance of Ruby classes and methods

Discussion:

1.  Introduction

2.  Interactive Ruby and Ruby development tools

Ruby interpreter C:\ruby\bin\irb.bat

3.  Integrated Development Environments (The search for a Ruby IDE)

Installed Aptana Studio

4.  Methods in Ruby

5.  Classes in Ruby

6.  Ruby Classes and the Rails framework revisited

ORM (Object Relational Mapping) using ActiveRecord.

To do:

1.  Spend some time moving your way through the 46 Ruby coding examples in the Ruby Tutorial with Code 

Done.

2. What are the syntax differences in the way that Ruby and Javascript use the if statement?

Ruby

  • elsif
  • no ()
  • no {} 
  • use of end

if condition1
code to be executed if condition1 is true
elsif condition2
code to be executed if condition2 is true
else
code to be executed if condition1 and condition2 are false
end

Javascript

  • else if
  • () around the conditions
  • use of {} around the code
  • no end statement

if (condition1)
{
code to be executed if condition1 is true
}
else if(condition2)
{
code to be executed if condition2 is true
}
else
{
code to be executed if condition1 and condition2 are false
}

3. While Ruby and Python are quite similar, can you find some similarities between Ruby and Javascript?

Both Ruby and Javascript are:

  • Object-oriented
  • interpreted
  • dynamically typed
  • incorporate metaprogramming techniques
  • blocks = first class functions

For some syntax differences see skim

Challenge Problems:

1.  Create, test and debug a Ruby program called dognames.rb or catnames.rb to accept 3 names from the keyboard and to display each name on the screen in alphabetical order WITHOUT using a data structure such as a list.

2. Write a Ruby program called fizzbuzz.rb that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

fizzbuzz.rb is available as a workshop resource via my.csu Interact so rather than reinvent the wheel I examined then ran it…

3.  Compare the Ruby and Python versions of the dog years calculator.

Ruby

#!/usr/bin/ruby
# The Dog year calculator program called dogyears.rb
 
def dogyears
# get the original age
  puts “Enter your age (in human years): “
  age = gets # gets is a method for input from keyboard
  puts # is a method or operator for screen output
 
#do some range checking, then print result
  if age < 0
    puts “Negative age?!?  I don’t think so.”
  elsif age < 3 or age > 110
    puts “Frankly, I don’t believe you.”
  else
    puts “That’s”, age*7, “in dog years.”
  end
dogyears

Python

#!/usr/bin/python
# The Dog year calculator program called dogyears.py
 
def dogyears():
# get the original age
    age = input(“Enter your age (in human years): “)
    print       # print a blank line
 
# do some range checking, then print result
    if age < 0:
       print “Negative age?!?  I don’t think so.”
    elif age < 3 or age > 110:
       print “Frankly, I don’t believe you.”
    else:
       print “That’s”, age*7, “in dog years.”
 
### pause for Return key (so window doesn’t disappear)
    raw_input(‘press Return>’)
 
def main():
    dogyears()
main()

Comparison:

  • Ruby:
    • Input: gets
    • Function: dogyears – no brackets
    • Output: puts
    • Else If: elsif
    • End: used
    • Main: not used
  • Python:
    • Input: input()
    • Function: dogyears() – with brackets
    • Output: print
    • Else If: elif
    • End: not used
    • Main: used

 

Workshop 3 – Online Taxi Booking System : MySQL and Database design

Topic objectives:

  • Develop a database object design for an online taxi booking system (OTBS);
  • Revise database techniques with Rails and SQL
  • Describe how to use the MVC “push-based architecture” in the Ruby on Rails development environment

 Discussion:

1.  Introduction

2. HelloWorld application in Ruby on Rails

3.  The SQL Model and Rails

4.  More clues on the OTBS database design

5.  Scaffolding and the concept of metaprogramming: doing more with less

6.  MySQL tools

To do:

1.  Set up the MySQL tools on your computer as described in section 6 above.

As I am running Windows I will download from MySQL tools.

MySQL Workbench provides DBAs and developers an integrated tools environment for:

  • Database Design & Modeling
  • SQL Development (replacing MySQL Query Browser) (Version 5.2 or later)
  • Database Administration (replacing MySQL Administrator) (Version 5.2 or later)

 

2.  Rails will setup a new application directory for each of your Web application projects. Get InstantRails (Windows) or Locomotive (MacOS) running on your machine. Both packages install Ruby, Rails, a Web server or one called ‘Mongrel’ or another small Ruby Web server called ‘WEBrick’, and MySQL “inside a bubble” as I call it so that others parts of your system are not modified (Similarly ZOPE does with installing its own Web server and Python versions).

Created the rail application taxi via the command rails taxi

 

taxi is now a rails application

and can be started with Mongrel

 

3.  Once Rails is running for you at http://localhost:3000, you need to configure database access. Connection to the database is specified in the config/database.yml file.

Rails is running at localhost:3000

Change database connection via the configuration file: config/database.yml

 

4.  Generate the Passenger model by creating the MySQL database and ‘passengers’ table from the information above.

Create MySQL database otbs_development

Edit a SQL script to create the passengers table and save as rails_apps\taxi\db\create.sql

Execute the create.sql script to create passengers in the otbs_development database

 Generate the Passenger model

 

 5.  Further work on understanding MySQL under Rails by David Mertz:

  1. See “Fast-track your Web apps with Ruby on Rails
  2. TheRolling with Ruby on Rails” series and “Cookbook recipes” by Curt Hibbs and others

Challenge Problems:

None – phew!

Workshop 2 – Model View Controller design approach

Topic objectives:

  • Describe the history and architecture of the Model View Controller (MVC) approach to Web application design
  • Revise database techniques with Rails and SQL
  • Describe how to use MVC in the Ruby on Rails development environment
  • Set up a focus group (like a study group for peer learning) to work on the Ruby on Rails workshops via Interact tools

Discussion:

To do:

1.  Set up a focus group (like a study group for peer learning) to work on the Ruby on Rails workshops via Interact tools as a class.

We have already been provided with a number of mechanisms to communicate on this subject:

  • forum
  • chat room
  • wiki

So far there has been little use of any of these.  I assume the other students are as time challenged as I am! 

 

2.  What is meant by “convention over configuration” and how does it reduce coding?

Configuration decisions are dictated by framework conventions so the programmer does not need to spend time making them nor writing configuration files.

 

3.  Further work on understanding MVC:

  1. See the wiki (error with link – this topic does not exist yet?)
  2. Do the MVC tutorial – Smalltalk-80, Squeak MVC UI or Morphic UI

Has a link to an MVC paper and this summary: 

  • “In the MVC paradigm the user input, the modeling of the external world, and the visual feedback to the user are explicitly separated and handled by three types of object, each specialized for its task.
    • The view manages the graphical and/or textual output to the portion of the bitmapped display that is allocated to its application.
    • The controller interprets the mouse and keyboard inputs from the user, commanding the model and/or the view to change as appropriate.
    • Finally, the model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller).”

 

4.  Got a spare hour or so? I recommend the UC Berkeley RAD lab’s Ruby on Rails Short course

Would like to find the time to do more of these and take notes as Armando is like Speedy Gonzales.

 

5.  Read the Flash article using ActionScript by Colin Moock The Model-View-Controller Design Pattern

 Skimmed.

Challenge Problems:

1. How is Rails structured to follow the MVC pattern?

Consider our project and examine the directories where Rails is located. 

If the data model is called Taxi (it is convention to name the model beginning with an upper case letter) then:

  • The model is a Ruby class located in app/models/taxi.rb
  • The SQL table is taxis – the pluralisation of the model
    • In our project we have 2 tables as passenger_origin and passenger_destination, where:
      • the table row = an object instance
      • each of the columns = an object attribute
  • The controller methods live in app/controllers/taxi_controller.rb
    • Each controller can access templates to display the input screen and methods for action
  • The views are kept in app/views/taxi/*.rhtml, where:
    • each *.rhtml maps to a controller method
    • In Rails, the view is rendered using RHTML or RXML.  According to the wiki page, RHTML is HTML with embedded Ruby code and RXML is Ruby-generated XML code.

If I look at one of the sample Ruby applications, cookbook, that shipped with Instant Rails (see Workshop 1):

Models:

  • cookbook/app/models/category.rb
  • cookbook/app/models/recipe.rb

Views:

  • cookbook/app/categories/edit.html.erb
  • cookbook/app/categories/index.html.erb
  • cookbook/app/categories/new.html.erb
  • cookbook/app/categories/show.html.erb
  • cookbook/app/recipes/_form.html.erb
  • cookbook/app/recipes/edit.html.erb
  • cookbook/app/recipes/index.html.erb
  • cookbook/app/recipes/new.html.erb
  • cookbook/app/recipes/show.html.erb

Controllers:

  • cookbook/app/controllers/categories_controller.rb
  • cookbook/app/controllers/recipes_controller.rb

Based upon the convention described we can deduce the following:

Data Models:

  • Category
  • Recipe

SQL tables:

  • categories
  • recipes

 

2. Apply the MVC design approach to our Project: Online Taxi Booking System.

HINT: Begin with a single model, single view and single controller classes. This will give you a head start to the next workshop: Online Taxi Booking System: SQL and Database design

Workshop 1 – Setting up the model railway

Topic objectives:

  • Install Ruby on Rails on your computer (InstantRails or Locomotive);
  • Learn about the Model View Controller (MVC) approach to Web application design;
  • Revise database techniques with MySQL
  • Learn how to use the Ruby on Rails development environment
  • Set up a focus group (like a study group for peer learning) to work on the Ruby on Rails workshops via Interact tools

Resources:

  • RailsSpace: Building a Social Networking Website with Ruby on Rails
  • Book list

To do:  

1.  Download iTunes and subscribe to the “Learning RailsPodcasts

As I already have iTunes I just subscribed to the Learning Rails online course and podcasts.

2. Install Ruby on Rails on your computer

The link above leads to Ruby Forge for downloading Ruby for Windows…

3. Rather than get Ruby on Rails running manually, you use the pre-packaged solutions. These include everything in one bundle: Web server, database, Ruby, Rails, the works.

a.  For OS X, there’s Locomotive.

b.  For Windows, there’s Instant Rails.

  •  …here there is no reference to Instant Rails and One-Click Installer is marked as (old) so I will go with RubyInstaller Release Candidate 2 (2010-02-06 22:00). 
  •  Need to register first (or do I?)
  • Downloading rubyinstaller-1.9.1-p378-rc2.exe
  • ..ok I found better directions for Instant Rails so firstly I uninstalled 1.9 and installed Instant Rails 2.0 via the InstantRails-2.0-win.zip from RubyForge.

Testing the installation:

Starting Instant Rails:

Using supplied cookbook application:

Starting with Mongrel:

Application success!:

Challenge Problems:

1.  Make a list of all programming languages and Web development tools used by you in prior experiences. Describe what you know about Web application frameworks before we begin.

Programming Languages

I have had experience with the following programming languages:

  • Pascal
  • IBM’s CSP (Cross System Product)
    • CSP2/AD
    • CSP/AD, CSP/AE
    • VisualGen
  • DB2
    • SQL/DS
    • SQL
    • QMF
  • COBOL
  • JCL
  • REXX
  • SQL* Forms
  • Unify Vision
  • VBA
  • SQL Server Reporting Services (SSRS)
  • C# .NET
  • .NET 3.5

Web Application Frameworks

I have had some experience with Microsoft Visual Studio working on SSRS and recently doing the .NET Framework 3.5 CSU units ITI530, ITE501 and ITE502 and their associated MCTS exams.  I understand a web application framework to be a development environment that supports the common tasks and services that are required to develop a web application.

2.  Ruby is “an interpreted scripting language” for quick and easy object-oriented programming”. Find out about the Ruby language and discover what this means.

Interpreted languages are stored as source code and interpreted at run time rather than compiled and stored as machine executable code.  Ruby uses an intermediate representation, in the form of an abstract syntax tree, which is compiled each time before execution by a bytecode interpreter.

Scripting languages are languages that allow the control of other software applications.  Examples include:

  • Job Control Languages (IBM’s JCL) and shells
  • GUI scripting
  • Application Specific languages
  • Web browsers (JavaScript)
  • Text processing languages
  • General purpose dynamic languages (Perl)
  • Extension embeddable languages

What is ruby? spells this out:

interpreted scripting language:

  • ability to make operating system calls directly
  • powerful string operations and regular expressions
  • immediate feedback during development

quick and easy:

  • variable declarations are unnecessary
  • variables are not typed
  • syntax is simple and consistent
  • memory management is automatic

object oriented programming:

  • everything is an object
  • classes, methods, inheritance, etc.
  • singleton methods
  • “mixin” functionality by module
  • iterators and closures

also:

  • multiple precision integers
  • convenient exception processing
  • dynamic loading
  • threading support

3.  What is Rails and how does it work with Ruby?

Ruby on Rails (a.k.a Rails) is an open-source Model-View-Controller (MVC) web development framework written in the Ruby language.  Rails is described as opinionated software because it makes assumptions about best practice and directs programmers to use these patterns or conventions, while discouraging others, to increase productivity.  It uses the following guiding principles:

Ruby provides a full suite of tools for creating web applications such as:

  • Action Controller – controller management
  • Action View – view management
  • Active Record – model management
  • Action Mailer – e-mail services
  • Active Resource – framework for managing the connection between business objects and web services
  • Railties – core Rails code
  • Active Support – utility classes and standard Ruby library extensions

4.  What is meant by “convention over configuration” in regards to the use of Rails in Web application development?

The Wikipedia definition: “Convention over Configuration (also known as Coding by convention) is a software design paradigm which seeks to decrease the number of decisions that developers need to make, gaining simplicity, but not necessarily losing flexibility”

Ruby on Rails states: “Convention Over Configuration- means that Rails makes assumptions about what you want to do and how you’re going to do it, rather than letting you tweak every little thing through endless configuration files.”

The concept is that by using the web framework conventions provided by Rails the amount of configuration required is reduced and hence productivity increased.

5.  When did Model-View-Controller begin and where is it used?

MVC is a software architectural design pattern first described in a 1979 paper by Trygve Reenskaug who was working on Smalltalk at Xerox PARC.  The MVC pattern is used in GUI and web frameworks.

6.  Describe the steps involved with the MVC design approach.

Workshops page

I have created a page for this at https://davebarnsley.wordpress.com/workshops-2/ and yep I can’t remove the -2 which I think is because I created then deleted a page named workshops…