Presentation is loading. Please wait.

Presentation is loading. Please wait.

Trestle Generator Industrial-strength scaffolding for Ruby on Rails web application development.

Similar presentations


Presentation on theme: "Trestle Generator Industrial-strength scaffolding for Ruby on Rails web application development."— Presentation transcript:

1 Trestle Generator Industrial-strength scaffolding for Ruby on Rails web application development

2 What is Rails scaffolding? One of the “wows” of early RoR demos One of the “wows” of early RoR demos Minimal generated code for access to a database table Minimal generated code for access to a database table A starting point for applications—you’ll augment and rework scaffolds into a full- fledged application A starting point for applications—you’ll augment and rework scaffolds into a full- fledged application

3 What does scaffolding give you? A model (if it doesn’t already exist) A model (if it doesn’t already exist) A controller with actions index, list, new, create, show, edit, update, and destroy A controller with actions index, list, new, create, show, edit, update, and destroy Four view templates: list, new, show, and edit Four view templates: list, new, show, and edit A view layout A view layout A stylesheet A stylesheet A helper class A helper class A unit test case (if it doesn’t already exist) A unit test case (if it doesn’t already exist) A functional test case A functional test case

4 Scaffolding demo (In case you’re unfamiliar with Rails scaffolds)

5 Start a new Rails application > rails bugcatcher... > cd bugcatcher >

6 Add a new model > script/generate model Issue exists app/models/ exists test/unit/ exists test/fixtures/ create app/models/issue.rb create test/unit/issue_test.rb create test/fixtures/issues.yml create db/migrate create db/migrate/001_create_issues.rb >

7 Describe the database table behind your model # (Editing the file 001_create_issues.rb) class CreateIssues < ActiveRecord::Migration def self.up create_table :issues do |t| t.column :created_at, :datetime t.column :subject, :string t.column :body, :text t.column :assigned_to, :string end def self.down drop_table :issues end

8 Create the database and table > mysqladmin --user=root create bugcatcher_development > rake migrate == CreateIssues: migrating =========================== -- create_table(:issues) -> 0.1100s == CreateIssues: migrated (0.1100s) ================== >

9 Build a scaffold for your model and point your browser at it > script/generate scaffold Issue... > script/server => Booting WEBrick... => Rails application started on http://0.0.0.0:3000 => Ctrl-C to shutdown server; call with --help for options [2006-05-13 16:00:00] INFO WEBrick 1.3.1 [2006-05-13 16:00:01] INFO ruby 1.8.4 (2005-12-24) [i386-mswin32] [2006-05-13 16:00:02] INFO WEBrick::HTTPServer#start: pid=4056 port=3000

10 Voilà—you’re on Rails

11 What’s wrong with scaffolding? Not much Not much Scaffold controllers are cluttered with too many actions Scaffold controllers are cluttered with too many actions Scaffold URL s are both pretty and hackable, but they can be made more so Scaffold URL s are both pretty and hackable, but they can be made more so Scaffold views do not degrade gracefully in the absence of JavaScript Scaffold views do not degrade gracefully in the absence of JavaScript

12 Scaffold: Too many actions URLResult /issues /issues/list Lists existing issue records /issues/newShows an empty issue /issues/createInserts a new issue /issues/show/99Shows the issue having ID 99 /issues/edit/99Shows an issue form for ID 99 /issues/update/99Updates the issue having ID 99 /issues/destroy/99Deletes the issue having ID 99

13 Trestle: No clutter URLMethodResult /issues GET / POST Lists existing issue records /issues/new GET Shows an empty issue POST Inserts a new issue /issues/99 GET / POST Shows the issue having ID 99 /issues/99/edit GET Shows an issue form for ID 99 POST Updates the issue having ID 99 /issues/99/destroy GET Redirects to edit with a notice POST Deletes the issue having ID 99

14 Scaffold: Pretty and hackable URL s /issues/edit/99 is Rubyish in that it reads well, but it breaks Google Toolbar’s Up One Level because /issues/edit leads nowhere /issues/edit/99 is Rubyish in that it reads well, but it breaks Google Toolbar’s Up One Level because /issues/edit leads nowhere Savvy users will explore your application by toying around with URL s—you should encourage this Savvy users will explore your application by toying around with URL s—you should encourage this URLs are an important part of your UI —make them as usable as possible URLs are an important part of your UI —make them as usable as possible

15 Trestle: Prettier and hackabler URL s /issues/99/edit has no invalid “parent directories” (/issues and /issues/99 work) /issues/99/edit has no invalid “parent directories” (/issues and /issues/99 work) Your application may have more complex URL s, but try to make all reasonable variations of any URL a valid destination: Your application may have more complex URL s, but try to make all reasonable variations of any URL a valid destination: –/ people / njonsson / issues / 99 / edit –/ calendar / 2006 / 5 / 13 ? view=me & feed=rss20 –/ dashboard / customize / widgets / top_right

16 Scaffold: JavaScript required The Destroy link on the list view produces an HTTP POST request with the help of JavaScript (an tag is transformed into a ) The Destroy link on the list view produces an HTTP POST request with the help of JavaScript (an tag is transformed into a ) If JavaScript is not present then the remains and a GET request is made instead of POST If JavaScript is not present then the remains and a GET request is made instead of POST The scaffold controller silently ignores the request— this is an acceptable response to Google Web Accelerator but is less than friendly to a person typing in his browser’s address bar The scaffold controller silently ignores the request— this is an acceptable response to Google Web Accelerator but is less than friendly to a person typing in his browser’s address bar

17 Trestle: JavaScript cool but not required The Destroy link works the same way on a trestle’s list view as it does on a scaffold’s list view The Destroy link works the same way on a trestle’s list view as it does on a scaffold’s list view But trestle’s edit view adds a Destroy button at the bottom of the form But trestle’s edit view adds a Destroy button at the bottom of the form The trestle controller redirects a GET request to the edit view, and it provides a flash notice instructing the user to click the Destroy button The trestle controller redirects a GET request to the edit view, and it provides a flash notice instructing the user to click the Destroy button

18

19 Trestle: Show me the tests test_list test_list test_new_using_get test_new_using_get test_new_using_post test_new_using_post test_show test_show test_show_without_id test_show_without_id test_edit_using_get test_edit_using_get test_edit_using_post test_edit_using_post test_edit_without_id test_edit_without_id test_destroy_using_get test_destroy_using_get test_destroy_using_post test_destroy_using_post test_destroy_without_id test_destroy_without_id Trestle controllers start your application off on the right foot with functional tests of the controller’s behavior.

20 Get trestle now > gem install trestle_generator Attempting local installation of ‘trestle_generator’ Local gem file not found: trestle_generator*.gem Attempting remote installation of ‘trestle_generator’ Updating Gem source index for: http://gems.rubyforge.org Successfully installed trestle_generator-1.1.5 >

21 Feed back Visit trestle.rubyforge.org Visit trestle.rubyforge.org Send mail to nils@alumni.rice.edu Send mail to nils@alumni.rice.edu


Download ppt "Trestle Generator Industrial-strength scaffolding for Ruby on Rails web application development."

Similar presentations


Ads by Google