environmentalist 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +58 -0
  3. data/README.txt +43 -0
  4. data/Rakefile +32 -0
  5. data/bin/environmentalize +84 -0
  6. data/environmentalist.gemspec +35 -0
  7. data/lib/conf/postboot.rb +38 -0
  8. data/lib/environmentalist.rb +1 -0
  9. data/lib/environmentalist/version.rb +20 -0
  10. data/test/rails210/README +256 -0
  11. data/test/rails210/Rakefile +10 -0
  12. data/test/rails210/app/controllers/application.rb +15 -0
  13. data/test/rails210/app/helpers/application_helper.rb +3 -0
  14. data/test/rails210/config/boot.rb +109 -0
  15. data/test/rails210/config/database.yml +19 -0
  16. data/test/rails210/config/environment.rb +67 -0
  17. data/test/rails210/config/environments/development.rb +17 -0
  18. data/test/rails210/config/environments/production.rb +22 -0
  19. data/test/rails210/config/environments/test.rb +22 -0
  20. data/test/rails210/config/initializers/inflections.rb +10 -0
  21. data/test/rails210/config/initializers/mime_types.rb +5 -0
  22. data/test/rails210/config/initializers/new_rails_defaults.rb +15 -0
  23. data/test/rails210/config/routes.rb +41 -0
  24. data/test/rails210/doc/README_FOR_APP +2 -0
  25. data/test/rails210/log/development.log +0 -0
  26. data/test/rails210/log/production.log +0 -0
  27. data/test/rails210/log/server.log +0 -0
  28. data/test/rails210/log/test.log +0 -0
  29. data/test/rails210/public/404.html +30 -0
  30. data/test/rails210/public/422.html +30 -0
  31. data/test/rails210/public/500.html +30 -0
  32. data/test/rails210/public/dispatch.cgi +10 -0
  33. data/test/rails210/public/dispatch.fcgi +24 -0
  34. data/test/rails210/public/dispatch.rb +10 -0
  35. data/test/rails210/public/favicon.ico +0 -0
  36. data/test/rails210/public/images/rails.png +0 -0
  37. data/test/rails210/public/index.html +274 -0
  38. data/test/rails210/public/javascripts/application.js +2 -0
  39. data/test/rails210/public/javascripts/controls.js +963 -0
  40. data/test/rails210/public/javascripts/dragdrop.js +972 -0
  41. data/test/rails210/public/javascripts/effects.js +1120 -0
  42. data/test/rails210/public/javascripts/prototype.js +4225 -0
  43. data/test/rails210/public/robots.txt +5 -0
  44. data/test/rails210/script/about +3 -0
  45. data/test/rails210/script/console +3 -0
  46. data/test/rails210/script/dbconsole +3 -0
  47. data/test/rails210/script/destroy +3 -0
  48. data/test/rails210/script/generate +3 -0
  49. data/test/rails210/script/performance/benchmarker +3 -0
  50. data/test/rails210/script/performance/profiler +3 -0
  51. data/test/rails210/script/performance/request +3 -0
  52. data/test/rails210/script/plugin +3 -0
  53. data/test/rails210/script/process/inspector +3 -0
  54. data/test/rails210/script/process/reaper +3 -0
  55. data/test/rails210/script/process/spawner +3 -0
  56. data/test/rails210/script/runner +3 -0
  57. data/test/rails210/script/server +3 -0
  58. data/test/rails210/test/test_helper.rb +38 -0
  59. data/test/rails210test/test/test_helper.rb +38 -0
  60. data/test/rails_version_test.rb +38 -0
  61. metadata +124 -0
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ === v0.1.0
2
+ 2008-08-04
3
+
4
+ * Initial Release: environmentalize executable will make environments first-class citizens in your rails app!
data/Manifest.txt ADDED
@@ -0,0 +1,58 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/environmentalize
6
+ environmentalist.gemspec
7
+ lib/conf/postboot.rb
8
+ lib/environmentalist.rb
9
+ lib/environmentalist/version.rb
10
+ test/rails210/README
11
+ test/rails210/Rakefile
12
+ test/rails210/app/controllers/application.rb
13
+ test/rails210/app/helpers/application_helper.rb
14
+ test/rails210/config/boot.rb
15
+ test/rails210/config/database.yml
16
+ test/rails210/config/environment.rb
17
+ test/rails210/config/environments/development.rb
18
+ test/rails210/config/environments/production.rb
19
+ test/rails210/config/environments/test.rb
20
+ test/rails210/config/initializers/inflections.rb
21
+ test/rails210/config/initializers/mime_types.rb
22
+ test/rails210/config/initializers/new_rails_defaults.rb
23
+ test/rails210/config/routes.rb
24
+ test/rails210/doc/README_FOR_APP
25
+ test/rails210/log/development.log
26
+ test/rails210/log/production.log
27
+ test/rails210/log/server.log
28
+ test/rails210/log/test.log
29
+ test/rails210/public/404.html
30
+ test/rails210/public/422.html
31
+ test/rails210/public/500.html
32
+ test/rails210/public/dispatch.cgi
33
+ test/rails210/public/dispatch.fcgi
34
+ test/rails210/public/dispatch.rb
35
+ test/rails210/public/favicon.ico
36
+ test/rails210/public/images/rails.png
37
+ test/rails210/public/index.html
38
+ test/rails210/public/javascripts/application.js
39
+ test/rails210/public/javascripts/controls.js
40
+ test/rails210/public/javascripts/dragdrop.js
41
+ test/rails210/public/javascripts/effects.js
42
+ test/rails210/public/javascripts/prototype.js
43
+ test/rails210/public/robots.txt
44
+ test/rails210/script/about
45
+ test/rails210/script/console
46
+ test/rails210/script/dbconsole
47
+ test/rails210/script/destroy
48
+ test/rails210/script/generate
49
+ test/rails210/script/performance/benchmarker
50
+ test/rails210/script/performance/profiler
51
+ test/rails210/script/performance/request
52
+ test/rails210/script/plugin
53
+ test/rails210/script/process/inspector
54
+ test/rails210/script/process/reaper
55
+ test/rails210/script/process/spawner
56
+ test/rails210/script/runner
57
+ test/rails210/script/server
58
+ test/rails_version_test.rb
data/README.txt ADDED
@@ -0,0 +1,43 @@
1
+ = environmentalist
2
+
3
+ * http://github.com/jtrupiano/environmentalist/tree/master
4
+
5
+ == DESCRIPTION:
6
+ Provides an executable that converts a rails app's config structure. The basic idea is that environments themselves are now first-class citizens, allowing you to create several environments (e.g. staging, prodtest, demo, etc.) in a clean, organized fashion. Each environment is given its own folder where it can store its own set of configuration files (think mongrel configs, apache configs, etc.) without polluting the top-leve config/ directory.
7
+
8
+ == SYNOPSIS:
9
+
10
+ FIX (code sample of usage)
11
+
12
+ == REQUIREMENTS:
13
+
14
+ * none, but it's really only useful with a rails app
15
+
16
+ == INSTALL:
17
+
18
+ * sudo gem install environmentalist
19
+
20
+ == LICENSE:
21
+
22
+ (The MIT License)
23
+
24
+ Copyright (c) 2008 FIX
25
+
26
+ Permission is hereby granted, free of charge, to any person obtaining
27
+ a copy of this software and associated documentation files (the
28
+ 'Software'), to deal in the Software without restriction, including
29
+ without limitation the rights to use, copy, modify, merge, publish,
30
+ distribute, sublicense, and/or sell copies of the Software, and to
31
+ permit persons to whom the Software is furnished to do so, subject to
32
+ the following conditions:
33
+
34
+ The above copyright notice and this permission notice shall be
35
+ included in all copies or substantial portions of the Software.
36
+
37
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
38
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
39
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
40
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
41
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
42
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
43
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/environmentalist.rb'
6
+ require "./lib/environmentalist/version"
7
+
8
+ PKG_NAME = "environmentalist"
9
+ PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
10
+ version = Environmentalist::Version::STRING.dup
11
+ if ENV['SNAPSHOT'].to_i == 1
12
+ version << "." << Time.now.utc.strftime("%Y%m%d%H%M%S")
13
+ end
14
+ PKG_VERSION = version
15
+ PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
16
+
17
+ Hoe.new(PKG_NAME, PKG_VERSION) do |p|
18
+ p.rubyforge_name = 'johntrupiano' # if different than lowercase project name
19
+ p.developer('John Trupiano', 'jtrupiano@gmail.com')
20
+ p.name = PKG_NAME
21
+ p.version = PKG_VERSION
22
+ p.author = "John Trupiano"
23
+ p.email = "jtrupiano@gmail.com"
24
+ p.description = %q(Provides an executable that converts a rails app's config structure. The basic idea is that environments themselves are now first-class citizens, allowing you to create several environments (e.g. staging, prodtest, demo, etc.) in a clean, organized fashion. Each environment is given its own folder where it can store its own set of configuration files (think mongrel configs, apache configs, etc.) without polluting the top-leve config/ direcotory.)
25
+ p.summary = p.description # More details later??
26
+ p.remote_rdoc_dir = PKG_NAME # Release to /PKG_NAME
27
+ # p.changes = p.paragraphs_of('CHANGELOG', 0..1).join("\n\n")
28
+ p.need_zip = true
29
+ p.need_tar = false
30
+ end
31
+
32
+ # vim: syntax=Ruby
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby
2
+ # environmentalize
3
+ # Author: John Trupiano
4
+
5
+ require 'fileutils'
6
+ include FileUtils
7
+
8
+ require 'yaml'
9
+
10
+ rails_root = ARGV[0] || '.'
11
+ puts "rails_root: #{rails_root}"
12
+ config_base = File.join(rails_root, 'config')
13
+ old_env_dir = File.join(config_base, 'environments')
14
+
15
+ %w(demo development production staging test).each do |env|
16
+ dir = File.join(config_base, env)
17
+ if !File.directory?(dir)
18
+ puts "mkdir -p #{dir}"
19
+ mkdir_p dir
20
+ end
21
+ old_env_file = File.join(old_env_dir, "#{env}.rb")
22
+ if File.exists?(old_env_file)
23
+ new_env_file = File.join(dir, "environment.rb")
24
+ puts "mv #{old_env_file} #{new_env_file}"
25
+ mv(old_env_file, new_env_file)
26
+ end
27
+ end
28
+
29
+ # Copy production for these guys if it wasn't already found
30
+ %w(demo staging).each do |env|
31
+ new_env_file = File.join(config_base, env, "environment.rb")
32
+ prod_env_file = File.join(config_base, "production", "environment.rb")
33
+ if !File.exists?(new_env_file)
34
+ puts "cp #{prod_env_file} #{new_env_file}"
35
+ cp(prod_env_file, new_env_file)
36
+ end
37
+ end
38
+
39
+ #cp $GEM_HOME/environmentalist-0.1.0/conf/postboot.rb config/postboot.rb
40
+ postboot = File.join(config_base, "postboot.rb")
41
+ if !File.exists?(postboot)
42
+ gem_postboot = File.dirname(__FILE__) + '/../lib/conf/postboot.rb'
43
+ puts "cp #{gem_postboot} #{postboot}"
44
+ cp(gem_postboot, postboot)
45
+ end
46
+
47
+ main_env_file = File.join(config_base, "environment.rb")
48
+ env_contents = File.open(main_env_file).read
49
+ if !env_contents.include?("require File.join(File.dirname(__FILE__), 'postboot')")
50
+
51
+ contents = <<-CONTENTS
52
+ # Load postboot file to change Rails paths
53
+ require File.join(File.dirname(__FILE__), 'postboot')
54
+
55
+ Rails::Initializer.run do |config|
56
+ CONTENTS
57
+
58
+ env_contents.sub!("Rails::Initializer.run do |config|", contents)
59
+ File.open(main_env_file, 'w') {|f| f.write(env_contents) }
60
+ end
61
+
62
+ if File.directory?(old_env_dir)
63
+ puts "Removing #{old_env_dir}"
64
+ rm_rf(old_env_dir)
65
+ end
66
+
67
+ # Handle database.yml now
68
+ old_db_yml = File.join(config_base, 'database.yml')
69
+ if File.exists?(old_db_yml)
70
+ y = YAML.load_file(old_db_yml)
71
+ %w(demo development production staging test).each do |env|
72
+ new_db_yml = File.join(config_base, env, 'database.yml')
73
+ if !File.exists?(new_db_yml)
74
+ if !y[env].nil?
75
+ puts "Writing #{new_db_yml}"
76
+ # remove all other keys
77
+ y_dup = y.reject {|key, value| key != env}
78
+ File.open(new_db_yml, 'w') {|f| f. write(y_dup.to_yaml) }
79
+ end
80
+ end
81
+ end
82
+ puts "Removing #{old_db_yml}"
83
+ rm_f(old_db_yml)
84
+ end
@@ -0,0 +1,35 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{environmentalist}
3
+ s.version = "0.1.0"
4
+
5
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
+ s.authors = ["John Trupiano"]
7
+ s.date = %q{2008-09-12}
8
+ s.default_executable = %q{environmentalize}
9
+ s.description = %q{Provides an executable that converts a rails app's config structure. The basic idea is that environments themselves are now first-class citizens, allowing you to create several environments (e.g. staging, prodtest, demo, etc.) in a clean, organized fashion. Each environment is given its own folder where it can store its own set of configuration files (think mongrel configs, apache configs, etc.) without polluting the top-leve config/ direcotory.}
10
+ s.email = %q{jtrupiano@gmail.com}
11
+ s.executables = ["environmentalize"]
12
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
13
+ s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/environmentalize", "environmentalist.gemspec", "lib/conf/postboot.rb", "lib/environmentalist.rb", "lib/environmentalist/version.rb", "test/rails210/README", "test/rails210/Rakefile", "test/rails210/app/controllers/application.rb", "test/rails210/app/helpers/application_helper.rb", "test/rails210/config/boot.rb", "test/rails210/config/database.yml", "test/rails210/config/environment.rb", "test/rails210/config/environments/development.rb", "test/rails210/config/environments/production.rb", "test/rails210/config/environments/test.rb", "test/rails210/config/initializers/inflections.rb", "test/rails210/config/initializers/mime_types.rb", "test/rails210/config/initializers/new_rails_defaults.rb", "test/rails210/config/routes.rb", "test/rails210/doc/README_FOR_APP", "test/rails210/log/development.log", "test/rails210/log/production.log", "test/rails210/log/server.log", "test/rails210/log/test.log", "test/rails210/public/404.html", "test/rails210/public/422.html", "test/rails210/public/500.html", "test/rails210/public/dispatch.cgi", "test/rails210/public/dispatch.fcgi", "test/rails210/public/dispatch.rb", "test/rails210/public/favicon.ico", "test/rails210/public/images/rails.png", "test/rails210/public/index.html", "test/rails210/public/javascripts/application.js", "test/rails210/public/javascripts/controls.js", "test/rails210/public/javascripts/dragdrop.js", "test/rails210/public/javascripts/effects.js", "test/rails210/public/javascripts/prototype.js", "test/rails210/public/robots.txt", "test/rails210/script/about", "test/rails210/script/console", "test/rails210/script/dbconsole", "test/rails210/script/destroy", "test/rails210/script/generate", "test/rails210/script/performance/benchmarker", "test/rails210/script/performance/profiler", "test/rails210/script/performance/request", "test/rails210/script/plugin", "test/rails210/script/process/inspector", "test/rails210/script/process/reaper", "test/rails210/script/process/spawner", "test/rails210/script/runner", "test/rails210/script/server", "test/rails_version_test.rb", "test/rails210/test/test_helper.rb", "test/rails210test/test/test_helper.rb"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://github.com/jtrupiano/environmentalist/tree/master}
16
+ s.rdoc_options = ["--main", "README.txt"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{johntrupiano}
19
+ s.rubygems_version = %q{1.2.0}
20
+ s.summary = %q{Provides an executable that converts a rails app's config structure. The basic idea is that environments themselves are now first-class citizens, allowing you to create several environments (e.g. staging, prodtest, demo, etc.) in a clean, organized fashion. Each environment is given its own folder where it can store its own set of configuration files (think mongrel configs, apache configs, etc.) without polluting the top-leve config/ direcotory.}
21
+ s.test_files = ["test/rails_version_test.rb"]
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 2
26
+
27
+ if current_version >= 3 then
28
+ s.add_development_dependency(%q<hoe>, [">= 1.7.0"])
29
+ else
30
+ s.add_dependency(%q<hoe>, [">= 1.7.0"])
31
+ end
32
+ else
33
+ s.add_dependency(%q<hoe>, [">= 1.7.0"])
34
+ end
35
+ end
@@ -0,0 +1,38 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ rails_env = ENV['RAILS_ENV'] || 'development'
4
+
5
+ env_dir = File.join(RAILS_ROOT, 'config', rails_env)
6
+ db_file = File.join(env_dir, 'database.yml')
7
+ env_file = File.join(env_dir, 'environment.rb')
8
+
9
+ unless File.exists?(env_dir)
10
+ puts "#{env_dir} environment directory cannot be found."
11
+ exit(1)
12
+ end
13
+
14
+ unless File.exists?(db_file)
15
+ puts "#{db_file} is missing. You cannot continue without this."
16
+ exit(1) # exit with an error code
17
+ end
18
+
19
+ unless File.exists?(env_file)
20
+ puts "#{env_file} environment file is missing."
21
+ exit(1)
22
+ end
23
+
24
+ # Now, let's open up Rails and tell it to find our environment files elsewhere.
25
+ module Rails
26
+ class Configuration
27
+
28
+ def database_configuration_file
29
+ File.join(root_path, 'config', environment, 'database.yml')
30
+ end
31
+
32
+ # The path to the current environment's file (development.rb, etc.). By
33
+ # default the file is at <tt>config/environments/#{environment}.rb</tt>.
34
+ def environment_path
35
+ "#{root_path}/config/#{environment}/environment.rb"
36
+ end
37
+ end
38
+ end
@@ -0,0 +1 @@
1
+ gem 'rails', '>= 2.0.2' # ensure rails is loaded
@@ -0,0 +1,20 @@
1
+ module Environmentalist
2
+ module Version #:nodoc:
3
+ # A method for comparing versions of required modules. It expects two
4
+ # arrays of integers as parameters, the first being the minimum version
5
+ # required, and the second being the actual version available. It returns
6
+ # true if the actual version is at least equal to the required version.
7
+ def self.check(required, actual) #:nodoc:
8
+ required = required.map { |v| "%06d" % v }.join(".")
9
+ actual = actual.map { |v| "%06d" % v }.join(".")
10
+ return actual >= required
11
+ end
12
+
13
+ MAJOR = 0
14
+ MINOR = 1
15
+ TINY = 0
16
+
17
+ STRING = [MAJOR, MINOR, TINY].join(".")
18
+ end
19
+ end
20
+
@@ -0,0 +1,256 @@
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 and lighttpd if they are installed, otherwise
40
+ Rails will use WEBrick, the webserver that ships with Ruby. When you run script/server,
41
+ Rails will check if Mongrel exists, then lighttpd and finally fall back to WEBrick. This ensures
42
+ that you can always get up and running quickly.
43
+
44
+ Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
45
+ suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
46
+ getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
47
+ More info at: http://mongrel.rubyforge.org
48
+
49
+ If Mongrel is not installed, Rails will look for lighttpd. It's considerably faster than
50
+ Mongrel and WEBrick and also suited for production use, but requires additional
51
+ installation and currently only works well on OS X/Unix (Windows users are encouraged
52
+ to start with Mongrel). We recommend version 1.4.11 and higher. You can download it from
53
+ http://www.lighttpd.net.
54
+
55
+ And finally, if neither Mongrel or lighttpd are installed, Rails will use the built-in Ruby
56
+ web server, WEBrick. WEBrick is a small Ruby web server suitable for development, but not
57
+ for production.
58
+
59
+ But of course its also possible to run Rails on any platform that supports FCGI.
60
+ Apache, LiteSpeed, IIS are just a few. For more information on FCGI,
61
+ please visit: http://wiki.rubyonrails.com/rails/pages/FastCGI
62
+
63
+
64
+ == Apache .htaccess example
65
+
66
+ # General Apache options
67
+ AddHandler fastcgi-script .fcgi
68
+ AddHandler cgi-script .cgi
69
+ Options +FollowSymLinks +ExecCGI
70
+
71
+ # If you don't want Rails to look in certain directories,
72
+ # use the following rewrite rules so that Apache won't rewrite certain requests
73
+ #
74
+ # Example:
75
+ # RewriteCond %{REQUEST_URI} ^/notrails.*
76
+ # RewriteRule .* - [L]
77
+
78
+ # Redirect all requests not available on the filesystem to Rails
79
+ # By default the cgi dispatcher is used which is very slow
80
+ #
81
+ # For better performance replace the dispatcher with the fastcgi one
82
+ #
83
+ # Example:
84
+ # RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
85
+ RewriteEngine On
86
+
87
+ # If your Rails application is accessed via an Alias directive,
88
+ # then you MUST also set the RewriteBase in this htaccess file.
89
+ #
90
+ # Example:
91
+ # Alias /myrailsapp /path/to/myrailsapp/public
92
+ # RewriteBase /myrailsapp
93
+
94
+ RewriteRule ^$ index.html [QSA]
95
+ RewriteRule ^([^.]+)$ $1.html [QSA]
96
+ RewriteCond %{REQUEST_FILENAME} !-f
97
+ RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
98
+
99
+ # In case Rails experiences terminal errors
100
+ # Instead of displaying this message you can supply a file here which will be rendered instead
101
+ #
102
+ # Example:
103
+ # ErrorDocument 500 /500.html
104
+
105
+ ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
106
+
107
+
108
+ == Debugging Rails
109
+
110
+ Sometimes your application goes wrong. Fortunately there are a lot of tools that
111
+ will help you debug it and get it back on the rails.
112
+
113
+ First area to check is the application log files. Have "tail -f" commands running
114
+ on the server.log and development.log. Rails will automatically display debugging
115
+ and runtime information to these files. Debugging info will also be shown in the
116
+ browser on requests from 127.0.0.1.
117
+
118
+ You can also log your own messages directly into the log file from your code using
119
+ the Ruby logger class from inside your controllers. Example:
120
+
121
+ class WeblogController < ActionController::Base
122
+ def destroy
123
+ @weblog = Weblog.find(params[:id])
124
+ @weblog.destroy
125
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
126
+ end
127
+ end
128
+
129
+ The result will be a message in your log file along the lines of:
130
+
131
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
132
+
133
+ More information on how to use the logger is at http://www.ruby-doc.org/core/
134
+
135
+ Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
136
+
137
+ * The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
138
+ * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
139
+
140
+ These two online (and free) books will bring you up to speed on the Ruby language
141
+ and also on programming in general.
142
+
143
+
144
+ == Debugger
145
+
146
+ Debugger support is available through the debugger command when you start your Mongrel or
147
+ Webrick server with --debugger. This means that you can break out of execution at any point
148
+ in the code, investigate and change the model, AND then resume execution!
149
+ You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
150
+ Example:
151
+
152
+ class WeblogController < ActionController::Base
153
+ def index
154
+ @posts = Post.find(:all)
155
+ debugger
156
+ end
157
+ end
158
+
159
+ So the controller will accept the action, run the first line, then present you
160
+ with a IRB prompt in the server window. Here you can do things like:
161
+
162
+ >> @posts.inspect
163
+ => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
164
+ #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
165
+ >> @posts.first.title = "hello from a debugger"
166
+ => "hello from a debugger"
167
+
168
+ ...and even better is that you can examine how your runtime objects actually work:
169
+
170
+ >> f = @posts.first
171
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
172
+ >> f.
173
+ Display all 152 possibilities? (y or n)
174
+
175
+ Finally, when you're ready to resume execution, you enter "cont"
176
+
177
+
178
+ == Console
179
+
180
+ You can interact with the domain model by starting the console through <tt>script/console</tt>.
181
+ Here you'll have all parts of the application configured, just like it is when the
182
+ application is running. You can inspect domain models, change values, and save to the
183
+ database. Starting the script without arguments will launch it in the development environment.
184
+ Passing an argument will specify a different environment, like <tt>script/console production</tt>.
185
+
186
+ To reload your controllers and models after launching the console run <tt>reload!</tt>
187
+
188
+ == dbconsole
189
+
190
+ You can go to the command line of your database directly through <tt>script/dbconsole</tt>.
191
+ You would be connected to the database with the credentials defined in database.yml.
192
+ Starting the script without arguments will connect you to the development database. Passing an
193
+ argument will connect you to a different database, like <tt>script/dbconsole production</tt>.
194
+ Currently works for mysql, postgresql and sqlite.
195
+
196
+ == Description of Contents
197
+
198
+ app
199
+ Holds all the code that's specific to this particular application.
200
+
201
+ app/controllers
202
+ Holds controllers that should be named like weblogs_controller.rb for
203
+ automated URL mapping. All controllers should descend from ApplicationController
204
+ which itself descends from ActionController::Base.
205
+
206
+ app/models
207
+ Holds models that should be named like post.rb.
208
+ Most models will descend from ActiveRecord::Base.
209
+
210
+ app/views
211
+ Holds the template files for the view that should be named like
212
+ weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
213
+ syntax.
214
+
215
+ app/views/layouts
216
+ Holds the template files for layouts to be used with views. This models the common
217
+ header/footer method of wrapping views. In your views, define a layout using the
218
+ <tt>layout :default</tt> and create a file named default.html.erb. Inside default.html.erb,
219
+ call <% yield %> to render the view using this layout.
220
+
221
+ app/helpers
222
+ Holds view helpers that should be named like weblogs_helper.rb. These are generated
223
+ for you automatically when using script/generate for controllers. Helpers can be used to
224
+ wrap functionality for your views into methods.
225
+
226
+ config
227
+ Configuration files for the Rails environment, the routing map, the database, and other dependencies.
228
+
229
+ db
230
+ Contains the database schema in schema.rb. db/migrate contains all
231
+ the sequence of Migrations for your schema.
232
+
233
+ doc
234
+ This directory is where your application documentation will be stored when generated
235
+ using <tt>rake doc:app</tt>
236
+
237
+ lib
238
+ Application specific libraries. Basically, any kind of custom code that doesn't
239
+ belong under controllers, models, or helpers. This directory is in the load path.
240
+
241
+ public
242
+ The directory available for the web server. Contains subdirectories for images, stylesheets,
243
+ and javascripts. Also contains the dispatchers and the default HTML files. This should be
244
+ set as the DOCUMENT_ROOT of your web server.
245
+
246
+ script
247
+ Helper scripts for automation and generation.
248
+
249
+ test
250
+ Unit and functional tests along with fixtures. When using the script/generate scripts, template
251
+ test files will be generated for you and placed in this directory.
252
+
253
+ vendor
254
+ External libraries that the application depends on. Also includes the plugins subdirectory.
255
+ If the app has frozen rails, those gems also go here, under vendor/rails/.
256
+ This directory is in the load path.