fizx-collapsed_routes 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/.document +5 -0
  2. data/.gitignore +5 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +86 -0
  5. data/Rakefile +48 -0
  6. data/VERSION +1 -0
  7. data/collapsed_routes.gemspec +136 -0
  8. data/lib/collapsed_routes.rb +53 -0
  9. data/spec/app/README +243 -0
  10. data/spec/app/Rakefile +10 -0
  11. data/spec/app/app/controllers/application_controller.rb +10 -0
  12. data/spec/app/app/controllers/comments_controller.rb +85 -0
  13. data/spec/app/app/controllers/posts_controller.rb +85 -0
  14. data/spec/app/app/controllers/users_controller.rb +85 -0
  15. data/spec/app/app/helpers/application_helper.rb +3 -0
  16. data/spec/app/app/helpers/comments_helper.rb +2 -0
  17. data/spec/app/app/helpers/posts_helper.rb +2 -0
  18. data/spec/app/app/helpers/users_helper.rb +2 -0
  19. data/spec/app/app/models/comment.rb +3 -0
  20. data/spec/app/app/models/post.rb +4 -0
  21. data/spec/app/app/models/user.rb +3 -0
  22. data/spec/app/app/views/comments/edit.html.erb +24 -0
  23. data/spec/app/app/views/comments/index.html.erb +24 -0
  24. data/spec/app/app/views/comments/new.html.erb +23 -0
  25. data/spec/app/app/views/comments/show.html.erb +18 -0
  26. data/spec/app/app/views/layouts/comments.html.erb +17 -0
  27. data/spec/app/app/views/layouts/posts.html.erb +17 -0
  28. data/spec/app/app/views/layouts/users.html.erb +17 -0
  29. data/spec/app/app/views/posts/edit.html.erb +24 -0
  30. data/spec/app/app/views/posts/index.html.erb +24 -0
  31. data/spec/app/app/views/posts/new.html.erb +23 -0
  32. data/spec/app/app/views/posts/show.html.erb +18 -0
  33. data/spec/app/app/views/users/edit.html.erb +16 -0
  34. data/spec/app/app/views/users/index.html.erb +20 -0
  35. data/spec/app/app/views/users/new.html.erb +15 -0
  36. data/spec/app/app/views/users/show.html.erb +8 -0
  37. data/spec/app/config/boot.rb +110 -0
  38. data/spec/app/config/database.yml +22 -0
  39. data/spec/app/config/environment.rb +41 -0
  40. data/spec/app/config/environments/development.rb +17 -0
  41. data/spec/app/config/environments/production.rb +28 -0
  42. data/spec/app/config/environments/test.rb +28 -0
  43. data/spec/app/config/initializers/backtrace_silencers.rb +7 -0
  44. data/spec/app/config/initializers/inflections.rb +10 -0
  45. data/spec/app/config/initializers/mime_types.rb +5 -0
  46. data/spec/app/config/initializers/new_rails_defaults.rb +19 -0
  47. data/spec/app/config/initializers/session_store.rb +15 -0
  48. data/spec/app/config/locales/en.yml +5 -0
  49. data/spec/app/config/routes.rb +7 -0
  50. data/spec/app/db/migrate/20090623181503_create_users.rb +13 -0
  51. data/spec/app/db/migrate/20090623181555_create_posts.rb +15 -0
  52. data/spec/app/db/migrate/20090623181609_create_comments.rb +15 -0
  53. data/spec/app/db/schema.rb +36 -0
  54. data/spec/app/db/test.sqlite3 +0 -0
  55. data/spec/app/doc/README_FOR_APP +2 -0
  56. data/spec/app/lib/tasks/rspec.rake +167 -0
  57. data/spec/app/log/.gitignore +1 -0
  58. data/spec/app/script/about +4 -0
  59. data/spec/app/script/autospec +6 -0
  60. data/spec/app/script/console +3 -0
  61. data/spec/app/script/dbconsole +3 -0
  62. data/spec/app/script/destroy +3 -0
  63. data/spec/app/script/generate +3 -0
  64. data/spec/app/script/performance/benchmarker +3 -0
  65. data/spec/app/script/performance/profiler +3 -0
  66. data/spec/app/script/plugin +3 -0
  67. data/spec/app/script/runner +3 -0
  68. data/spec/app/script/server +3 -0
  69. data/spec/app/script/spec +10 -0
  70. data/spec/app/script/spec_server +9 -0
  71. data/spec/app/tmp/.gitignore +4 -0
  72. data/spec/collapsed_routes_spec.rb +39 -0
  73. data/spec/spec_helper.rb +13 -0
  74. metadata +153 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Kyle Maxwell
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,86 @@
1
+ = collapsed_routes
2
+
3
+ collapsed_routes is a gem to make hierarchical resource routing easier. Here's an example:
4
+
5
+ ActionController::Routing::Routes.draw do |map|
6
+ map.resources :users do |user|
7
+ user.resources :posts do |post|
8
+ post.resources :comments
9
+ end
10
+ end
11
+ end
12
+
13
+ If you execute:
14
+
15
+ require "collapsed_routes"
16
+ CollapsedRoutes.collapsed_routes :users, :posts, :comments
17
+
18
+ This will generate the following url_helpers:
19
+
20
+ def comment_path(comment = @comment)
21
+ user_post_comment_path(comment.post.user, comment.post, comment)
22
+ end
23
+
24
+ def edit_comment_path(comment = @comment)
25
+ edit_user_post_comment_path(comment.post.user, comment.post, comment)
26
+ end
27
+
28
+ def new_comment_path(post = @post)
29
+ new_user_post_comment_path(post.user, post)
30
+ end
31
+
32
+ def comments_path(post = @post)
33
+ user_post_comments_path(post.user, post)
34
+ end
35
+
36
+ def comment_url(comment = @comment)
37
+ user_post_comment_url(comment.post.user, comment.post, comment)
38
+ end
39
+
40
+ def edit_comment_url(comment = @comment)
41
+ edit_user_post_comment_url(comment.post.user, comment.post, comment)
42
+ end
43
+
44
+ def new_comment_url(post = @post)
45
+ new_user_post_comment_url(post.user, post)
46
+ end
47
+
48
+ def comments_url(post = @post)
49
+ user_post_comments_url(post.user, post)
50
+ end
51
+
52
+ def post_path(post = @post)
53
+ user_post_path(post.user, post)
54
+ end
55
+
56
+ def edit_post_path(post = @post)
57
+ edit_user_post_path(post.user, post)
58
+ end
59
+
60
+ def new_post_path(user = @user)
61
+ new_user_post_path(user)
62
+ end
63
+
64
+ def posts_path(user = @user)
65
+ user_posts_path(user)
66
+ end
67
+
68
+ def post_url(post = @post)
69
+ user_post_url(post.user, post)
70
+ end
71
+
72
+ def edit_post_url(post = @post)
73
+ edit_user_post_url(post.user, post)
74
+ end
75
+
76
+ def new_post_url(user = @user)
77
+ new_user_post_url(user)
78
+ end
79
+
80
+ def posts_url(user = @user)
81
+ user_posts_url(user)
82
+ end
83
+
84
+ == Copyright
85
+
86
+ Copyright (c) 2009 Kyle Maxwell. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "collapsed_routes"
8
+ gem.summary = %Q{TODO}
9
+ gem.email = "kyle@kylemaxwell.com"
10
+ gem.homepage = "http://github.com/fizx/collapsed_routes"
11
+ gem.authors = ["Kyle Maxwell"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'spec/rake/spectask'
20
+ Spec::Rake::SpecTask.new(:spec) do |spec|
21
+ spec.libs << 'lib' << 'spec'
22
+ spec.spec_files = FileList['spec/**/*_spec.rb']
23
+ end
24
+
25
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
26
+ spec.libs << 'lib' << 'spec'
27
+ spec.pattern = 'spec/**/*_spec.rb'
28
+ spec.rcov = true
29
+ end
30
+
31
+
32
+ task :default => :spec
33
+
34
+ require 'rake/rdoctask'
35
+ Rake::RDocTask.new do |rdoc|
36
+ if File.exist?('VERSION.yml')
37
+ config = YAML.load(File.read('VERSION.yml'))
38
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
39
+ else
40
+ version = ""
41
+ end
42
+
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = "collapsed_routes #{version}"
45
+ rdoc.rdoc_files.include('README*')
46
+ rdoc.rdoc_files.include('lib/**/*.rb')
47
+ end
48
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.2
@@ -0,0 +1,136 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{collapsed_routes}
5
+ s.version = "1.0.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Kyle Maxwell"]
9
+ s.date = %q{2009-06-23}
10
+ s.email = %q{kyle@kylemaxwell.com}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".document",
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "collapsed_routes.gemspec",
23
+ "lib/collapsed_routes.rb",
24
+ "spec/app/README",
25
+ "spec/app/Rakefile",
26
+ "spec/app/app/controllers/application_controller.rb",
27
+ "spec/app/app/controllers/comments_controller.rb",
28
+ "spec/app/app/controllers/posts_controller.rb",
29
+ "spec/app/app/controllers/users_controller.rb",
30
+ "spec/app/app/helpers/application_helper.rb",
31
+ "spec/app/app/helpers/comments_helper.rb",
32
+ "spec/app/app/helpers/posts_helper.rb",
33
+ "spec/app/app/helpers/users_helper.rb",
34
+ "spec/app/app/models/comment.rb",
35
+ "spec/app/app/models/post.rb",
36
+ "spec/app/app/models/user.rb",
37
+ "spec/app/app/views/comments/edit.html.erb",
38
+ "spec/app/app/views/comments/index.html.erb",
39
+ "spec/app/app/views/comments/new.html.erb",
40
+ "spec/app/app/views/comments/show.html.erb",
41
+ "spec/app/app/views/layouts/comments.html.erb",
42
+ "spec/app/app/views/layouts/posts.html.erb",
43
+ "spec/app/app/views/layouts/users.html.erb",
44
+ "spec/app/app/views/posts/edit.html.erb",
45
+ "spec/app/app/views/posts/index.html.erb",
46
+ "spec/app/app/views/posts/new.html.erb",
47
+ "spec/app/app/views/posts/show.html.erb",
48
+ "spec/app/app/views/users/edit.html.erb",
49
+ "spec/app/app/views/users/index.html.erb",
50
+ "spec/app/app/views/users/new.html.erb",
51
+ "spec/app/app/views/users/show.html.erb",
52
+ "spec/app/config/boot.rb",
53
+ "spec/app/config/database.yml",
54
+ "spec/app/config/environment.rb",
55
+ "spec/app/config/environments/development.rb",
56
+ "spec/app/config/environments/production.rb",
57
+ "spec/app/config/environments/test.rb",
58
+ "spec/app/config/initializers/backtrace_silencers.rb",
59
+ "spec/app/config/initializers/inflections.rb",
60
+ "spec/app/config/initializers/mime_types.rb",
61
+ "spec/app/config/initializers/new_rails_defaults.rb",
62
+ "spec/app/config/initializers/session_store.rb",
63
+ "spec/app/config/locales/en.yml",
64
+ "spec/app/config/routes.rb",
65
+ "spec/app/db/migrate/20090623181503_create_users.rb",
66
+ "spec/app/db/migrate/20090623181555_create_posts.rb",
67
+ "spec/app/db/migrate/20090623181609_create_comments.rb",
68
+ "spec/app/db/schema.rb",
69
+ "spec/app/db/test.sqlite3",
70
+ "spec/app/doc/README_FOR_APP",
71
+ "spec/app/lib/tasks/rspec.rake",
72
+ "spec/app/log/.gitignore",
73
+ "spec/app/script/about",
74
+ "spec/app/script/autospec",
75
+ "spec/app/script/console",
76
+ "spec/app/script/dbconsole",
77
+ "spec/app/script/destroy",
78
+ "spec/app/script/generate",
79
+ "spec/app/script/performance/benchmarker",
80
+ "spec/app/script/performance/profiler",
81
+ "spec/app/script/plugin",
82
+ "spec/app/script/runner",
83
+ "spec/app/script/server",
84
+ "spec/app/script/spec",
85
+ "spec/app/script/spec_server",
86
+ "spec/app/tmp/.gitignore",
87
+ "spec/collapsed_routes_spec.rb",
88
+ "spec/spec_helper.rb"
89
+ ]
90
+ s.has_rdoc = true
91
+ s.homepage = %q{http://github.com/fizx/collapsed_routes}
92
+ s.rdoc_options = ["--charset=UTF-8"]
93
+ s.require_paths = ["lib"]
94
+ s.rubygems_version = %q{1.3.2}
95
+ s.summary = %q{TODO}
96
+ s.test_files = [
97
+ "spec/app/app/controllers/application_controller.rb",
98
+ "spec/app/app/controllers/comments_controller.rb",
99
+ "spec/app/app/controllers/posts_controller.rb",
100
+ "spec/app/app/controllers/users_controller.rb",
101
+ "spec/app/app/helpers/application_helper.rb",
102
+ "spec/app/app/helpers/comments_helper.rb",
103
+ "spec/app/app/helpers/posts_helper.rb",
104
+ "spec/app/app/helpers/users_helper.rb",
105
+ "spec/app/app/models/comment.rb",
106
+ "spec/app/app/models/post.rb",
107
+ "spec/app/app/models/user.rb",
108
+ "spec/app/config/boot.rb",
109
+ "spec/app/config/environment.rb",
110
+ "spec/app/config/environments/development.rb",
111
+ "spec/app/config/environments/production.rb",
112
+ "spec/app/config/environments/test.rb",
113
+ "spec/app/config/initializers/backtrace_silencers.rb",
114
+ "spec/app/config/initializers/inflections.rb",
115
+ "spec/app/config/initializers/mime_types.rb",
116
+ "spec/app/config/initializers/new_rails_defaults.rb",
117
+ "spec/app/config/initializers/session_store.rb",
118
+ "spec/app/config/routes.rb",
119
+ "spec/app/db/migrate/20090623181503_create_users.rb",
120
+ "spec/app/db/migrate/20090623181555_create_posts.rb",
121
+ "spec/app/db/migrate/20090623181609_create_comments.rb",
122
+ "spec/app/db/schema.rb",
123
+ "spec/collapsed_routes_spec.rb",
124
+ "spec/spec_helper.rb"
125
+ ]
126
+
127
+ if s.respond_to? :specification_version then
128
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
129
+ s.specification_version = 3
130
+
131
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
132
+ else
133
+ end
134
+ else
135
+ end
136
+ end
@@ -0,0 +1,53 @@
1
+ module CollapsedRoutes
2
+ def collapsed_routes(*names)
3
+ names.map!(&:to_s)
4
+ names.each_with_index do |name, i|
5
+ next if i == 0
6
+ subset = names.first(i + 1)
7
+ collapse subset
8
+ end
9
+ end
10
+
11
+ private
12
+
13
+ def backtrack(list)
14
+ back = []
15
+ list.each_with_index do |_, i|
16
+ back << list.first(i + 1).join(".")
17
+ end
18
+ back.reverse.join(", ")
19
+ end
20
+
21
+ def collapse(names)
22
+ base = names[-1].singularize
23
+ parent = names[-2].singularize
24
+ series = names.map(&:singularize).join("_")
25
+ reversed = names.reverse.map(&:singularize)
26
+
27
+ backtrack_base = backtrack reversed
28
+ reversed.shift
29
+ backtrack_parent = backtrack reversed
30
+
31
+ %w[path url].each do |path|
32
+ ActionController::UrlWriter.module_eval <<-RUBY
33
+ def #{base}_#{path}(#{base} = @#{base})
34
+ #{series}_#{path}(#{backtrack_base})
35
+ end
36
+
37
+ def edit_#{base}_#{path}(#{base} = @#{base})
38
+ edit_#{series}_#{path}(#{backtrack_base})
39
+ end
40
+
41
+ def new_#{base}_#{path}(#{parent} = @#{parent})
42
+ new_#{series}_#{path}(#{backtrack_parent})
43
+ end
44
+
45
+ def #{base.pluralize}_#{path}(#{parent} = @#{parent})
46
+ #{series.pluralize}_#{path}(#{backtrack_parent})
47
+ end
48
+ RUBY
49
+ end
50
+ end
51
+
52
+ extend self
53
+ end
data/spec/app/README ADDED
@@ -0,0 +1,243 @@
1
+ == Welcome to Rails
2
+
3
+ Rails is a web-application framework that includes everything needed to create
4
+ database-backed web applications according to the Model-View-Control pattern.
5
+
6
+ This pattern splits the view (also called the presentation) into "dumb" templates
7
+ that are primarily responsible for inserting pre-built data in between HTML tags.
8
+ The model contains the "smart" domain objects (such as Account, Product, Person,
9
+ Post) that holds all the business logic and knows how to persist themselves to
10
+ a database. The controller handles the incoming requests (such as Save New Account,
11
+ Update Product, Show Post) by manipulating the model and directing data to the view.
12
+
13
+ In Rails, the model is handled by what's called an object-relational mapping
14
+ layer entitled Active Record. This layer allows you to present the data from
15
+ database rows as objects and embellish these data objects with business logic
16
+ methods. You can read more about Active Record in
17
+ link:files/vendor/rails/activerecord/README.html.
18
+
19
+ The controller and view are handled by the Action Pack, which handles both
20
+ layers by its two parts: Action View and Action Controller. These two layers
21
+ are bundled in a single package due to their heavy interdependence. This is
22
+ unlike the relationship between the Active Record and Action Pack that is much
23
+ more separate. Each of these packages can be used independently outside of
24
+ Rails. You can read more about Action Pack in
25
+ link:files/vendor/rails/actionpack/README.html.
26
+
27
+
28
+ == Getting Started
29
+
30
+ 1. At the command prompt, start a new Rails application using the <tt>rails</tt> command
31
+ and your application name. Ex: rails myapp
32
+ 2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
33
+ 3. Go to http://localhost:3000/ and get "Welcome aboard: You're riding the Rails!"
34
+ 4. Follow the guidelines to start developing your application
35
+
36
+
37
+ == Web Servers
38
+
39
+ By default, Rails will try to use Mongrel if it's are installed when started with script/server, otherwise Rails will use WEBrick, the webserver that ships with Ruby. But you can also use Rails
40
+ with a variety of other web servers.
41
+
42
+ Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
43
+ suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
44
+ getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
45
+ More info at: http://mongrel.rubyforge.org
46
+
47
+ Say other Ruby web servers like Thin and Ebb or regular web servers like Apache or LiteSpeed or
48
+ Lighttpd or IIS. The Ruby web servers are run through Rack and the latter can either be setup to use
49
+ FCGI or proxy to a pack of Mongrels/Thin/Ebb servers.
50
+
51
+ == Apache .htaccess example for FCGI/CGI
52
+
53
+ # General Apache options
54
+ AddHandler fastcgi-script .fcgi
55
+ AddHandler cgi-script .cgi
56
+ Options +FollowSymLinks +ExecCGI
57
+
58
+ # If you don't want Rails to look in certain directories,
59
+ # use the following rewrite rules so that Apache won't rewrite certain requests
60
+ #
61
+ # Example:
62
+ # RewriteCond %{REQUEST_URI} ^/notrails.*
63
+ # RewriteRule .* - [L]
64
+
65
+ # Redirect all requests not available on the filesystem to Rails
66
+ # By default the cgi dispatcher is used which is very slow
67
+ #
68
+ # For better performance replace the dispatcher with the fastcgi one
69
+ #
70
+ # Example:
71
+ # RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
72
+ RewriteEngine On
73
+
74
+ # If your Rails application is accessed via an Alias directive,
75
+ # then you MUST also set the RewriteBase in this htaccess file.
76
+ #
77
+ # Example:
78
+ # Alias /myrailsapp /path/to/myrailsapp/public
79
+ # RewriteBase /myrailsapp
80
+
81
+ RewriteRule ^$ index.html [QSA]
82
+ RewriteRule ^([^.]+)$ $1.html [QSA]
83
+ RewriteCond %{REQUEST_FILENAME} !-f
84
+ RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
85
+
86
+ # In case Rails experiences terminal errors
87
+ # Instead of displaying this message you can supply a file here which will be rendered instead
88
+ #
89
+ # Example:
90
+ # ErrorDocument 500 /500.html
91
+
92
+ ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
93
+
94
+
95
+ == Debugging Rails
96
+
97
+ Sometimes your application goes wrong. Fortunately there are a lot of tools that
98
+ will help you debug it and get it back on the rails.
99
+
100
+ First area to check is the application log files. Have "tail -f" commands running
101
+ on the server.log and development.log. Rails will automatically display debugging
102
+ and runtime information to these files. Debugging info will also be shown in the
103
+ browser on requests from 127.0.0.1.
104
+
105
+ You can also log your own messages directly into the log file from your code using
106
+ the Ruby logger class from inside your controllers. Example:
107
+
108
+ class WeblogController < ActionController::Base
109
+ def destroy
110
+ @weblog = Weblog.find(params[:id])
111
+ @weblog.destroy
112
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
113
+ end
114
+ end
115
+
116
+ The result will be a message in your log file along the lines of:
117
+
118
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
119
+
120
+ More information on how to use the logger is at http://www.ruby-doc.org/core/
121
+
122
+ Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
123
+
124
+ * The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
125
+ * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
126
+
127
+ These two online (and free) books will bring you up to speed on the Ruby language
128
+ and also on programming in general.
129
+
130
+
131
+ == Debugger
132
+
133
+ Debugger support is available through the debugger command when you start your Mongrel or
134
+ Webrick server with --debugger. This means that you can break out of execution at any point
135
+ in the code, investigate and change the model, AND then resume execution!
136
+ You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
137
+ Example:
138
+
139
+ class WeblogController < ActionController::Base
140
+ def index
141
+ @posts = Post.find(:all)
142
+ debugger
143
+ end
144
+ end
145
+
146
+ So the controller will accept the action, run the first line, then present you
147
+ with a IRB prompt in the server window. Here you can do things like:
148
+
149
+ >> @posts.inspect
150
+ => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
151
+ #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
152
+ >> @posts.first.title = "hello from a debugger"
153
+ => "hello from a debugger"
154
+
155
+ ...and even better is that you can examine how your runtime objects actually work:
156
+
157
+ >> f = @posts.first
158
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
159
+ >> f.
160
+ Display all 152 possibilities? (y or n)
161
+
162
+ Finally, when you're ready to resume execution, you enter "cont"
163
+
164
+
165
+ == Console
166
+
167
+ You can interact with the domain model by starting the console through <tt>script/console</tt>.
168
+ Here you'll have all parts of the application configured, just like it is when the
169
+ application is running. You can inspect domain models, change values, and save to the
170
+ database. Starting the script without arguments will launch it in the development environment.
171
+ Passing an argument will specify a different environment, like <tt>script/console production</tt>.
172
+
173
+ To reload your controllers and models after launching the console run <tt>reload!</tt>
174
+
175
+ == dbconsole
176
+
177
+ You can go to the command line of your database directly through <tt>script/dbconsole</tt>.
178
+ You would be connected to the database with the credentials defined in database.yml.
179
+ Starting the script without arguments will connect you to the development database. Passing an
180
+ argument will connect you to a different database, like <tt>script/dbconsole production</tt>.
181
+ Currently works for mysql, postgresql and sqlite.
182
+
183
+ == Description of Contents
184
+
185
+ app
186
+ Holds all the code that's specific to this particular application.
187
+
188
+ app/controllers
189
+ Holds controllers that should be named like weblogs_controller.rb for
190
+ automated URL mapping. All controllers should descend from ApplicationController
191
+ which itself descends from ActionController::Base.
192
+
193
+ app/models
194
+ Holds models that should be named like post.rb.
195
+ Most models will descend from ActiveRecord::Base.
196
+
197
+ app/views
198
+ Holds the template files for the view that should be named like
199
+ weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
200
+ syntax.
201
+
202
+ app/views/layouts
203
+ Holds the template files for layouts to be used with views. This models the common
204
+ header/footer method of wrapping views. In your views, define a layout using the
205
+ <tt>layout :default</tt> and create a file named default.html.erb. Inside default.html.erb,
206
+ call <% yield %> to render the view using this layout.
207
+
208
+ app/helpers
209
+ Holds view helpers that should be named like weblogs_helper.rb. These are generated
210
+ for you automatically when using script/generate for controllers. Helpers can be used to
211
+ wrap functionality for your views into methods.
212
+
213
+ config
214
+ Configuration files for the Rails environment, the routing map, the database, and other dependencies.
215
+
216
+ db
217
+ Contains the database schema in schema.rb. db/migrate contains all
218
+ the sequence of Migrations for your schema.
219
+
220
+ doc
221
+ This directory is where your application documentation will be stored when generated
222
+ using <tt>rake doc:app</tt>
223
+
224
+ lib
225
+ Application specific libraries. Basically, any kind of custom code that doesn't
226
+ belong under controllers, models, or helpers. This directory is in the load path.
227
+
228
+ public
229
+ The directory available for the web server. Contains subdirectories for images, stylesheets,
230
+ and javascripts. Also contains the dispatchers and the default HTML files. This should be
231
+ set as the DOCUMENT_ROOT of your web server.
232
+
233
+ script
234
+ Helper scripts for automation and generation.
235
+
236
+ test
237
+ Unit and functional tests along with fixtures. When using the script/generate scripts, template
238
+ test files will be generated for you and placed in this directory.
239
+
240
+ vendor
241
+ External libraries that the application depends on. Also includes the plugins subdirectory.
242
+ If the app has frozen rails, those gems also go here, under vendor/rails/.
243
+ This directory is in the load path.
data/spec/app/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require(File.join(File.dirname(__FILE__), 'config', 'boot'))
5
+
6
+ require 'rake'
7
+ require 'rake/testtask'
8
+ require 'rake/rdoctask'
9
+
10
+ require 'tasks/rails'
@@ -0,0 +1,10 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class ApplicationController < ActionController::Base
5
+ helper :all # include all helpers, all the time
6
+ protect_from_forgery # See ActionController::RequestForgeryProtection for details
7
+
8
+ # Scrub sensitive parameters from your log
9
+ # filter_parameter_logging :password
10
+ end