CS 683 Emerging Technologies Fall Semester, 2005 Doc 21 Rails Intro Nov 10, 2005 Copyright ©, All rights reserved SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA USA. OpenContent ( license defines the copyright on this document.
2 References Agile Web Development with Rails, Thomas & Hansson, Pragmatic Bookshelf, Main Ruby on Rails site Lots of howtos
3 Rails Architecture
4 Model-View-Controller Model Core functionality & data View Displays information to user Controller Handles user input Created by Trygve Reenskaug
5 Installing Rails Make sure Ruby & Gems is installed ruby -v gem --version If not installed use installer at gem install rails --include-dependencies For more information see:
6 Hello World Example Create a new application Al 40->rails demo Al 41->cd demo Al 42->ls README config/ log/ vendor/ Rakefile db/ public/ app/ doc/ script/ components/ lib/ test/ Run the Rails Webserver - WEBrick Al 43->ruby script/server Access the server at
7 Generating Controllers and Tests Al 15->ruby script/generate controller Say exists app/controllers/ exists app/helpers/ create app/views/say exists test/functional/ create app/controllers/say_controller.rb create test/functional/say_controller_test.rb create app/helpers/say_helper.rb
8 Complete Hello Example class SayController < ApplicationController def hello end hello Hello from Rails demo/app/controllers/say_controller.rb edit to be: demo/app/views/say/hello.rhtml new file Access page via
9 Dynamic Page class SayController < ApplicationController def = Time.now end hello It is now = Hello demo/app/controllers/say_controller.rbdemo/app/views/say/hello.rhtml
10 Links hello Say GoodBye "goodbye" %> class SayController < ApplicationController def = Time.now end def goodbye end Bye Goodbye Say <%= link_to( "Hello", :action => "hello") %> demo/app/controllers/say_controller.rb demo/app/views/say/goodbye.rhtmldemo/app/views/say/hello.rhtml