erector 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. data/README.txt +0 -4
  2. data/VERSION.yml +1 -1
  3. data/lib/erector.rb +2 -4
  4. data/lib/erector/abstract_widget.rb +2 -1
  5. data/lib/erector/erect/erect.rb +17 -14
  6. data/lib/erector/erect/rhtml.treetop +18 -10
  7. data/lib/erector/externals.rb +7 -1
  8. data/lib/erector/html.rb +30 -39
  9. data/lib/erector/rails.rb +6 -26
  10. data/lib/erector/rails/form_builder.rb +36 -0
  11. data/lib/erector/rails/railtie.rb +11 -0
  12. data/lib/erector/rails/template_handler.rb +16 -0
  13. data/lib/erector/rails/widget_renderer.rb +6 -0
  14. data/lib/erector/rails2.rb +27 -0
  15. data/lib/erector/{rails → rails2}/extensions/action_controller.rb +1 -1
  16. data/lib/erector/{rails → rails2}/extensions/rails_helpers.rb +17 -4
  17. data/lib/erector/{rails → rails2}/extensions/rails_widget.rb +6 -3
  18. data/lib/erector/{rails → rails2}/rails_form_builder.rb +0 -0
  19. data/lib/erector/rails2/rails_version.rb +6 -0
  20. data/lib/erector/{rails → rails2}/template_handlers/ert_handler.rb +0 -0
  21. data/lib/erector/{rails → rails2}/template_handlers/rb_handler.rb +2 -2
  22. data/lib/erector/rails3.rb +208 -0
  23. data/lib/erector/raw_string.rb +4 -0
  24. data/lib/erector/widgets/external_renderer.rb +8 -0
  25. data/spec/erect/erect_rails_spec.rb +34 -49
  26. data/spec/erect/erected_spec.rb +11 -0
  27. data/spec/rails2/erect_rails_spec.rb +114 -0
  28. data/spec/rails2/rails_app/Gemfile +12 -0
  29. data/spec/rails2/rails_app/Gemfile.lock +89 -0
  30. data/spec/rails2/rails_app/README +243 -0
  31. data/spec/rails2/rails_app/Rakefile +19 -0
  32. data/spec/rails2/rails_app/app/controllers/application_controller.rb +10 -0
  33. data/spec/rails2/rails_app/app/helpers/application_helper.rb +3 -0
  34. data/spec/rails2/rails_app/app/views/test/_erb.erb +1 -0
  35. data/spec/rails2/rails_app/app/views/test/_erector.rb +5 -0
  36. data/spec/rails2/rails_app/app/views/test/_partial_with_locals.rb +7 -0
  37. data/spec/rails2/rails_app/app/views/test/bare.rb +5 -0
  38. data/spec/rails2/rails_app/app/views/test/erb_from_erector.html.rb +5 -0
  39. data/spec/rails2/rails_app/app/views/test/erector_from_erb.html.erb +1 -0
  40. data/spec/rails2/rails_app/app/views/test/erector_with_locals_from_erb.html.erb +6 -0
  41. data/spec/rails2/rails_app/app/views/test/implicit_assigns.html.rb +5 -0
  42. data/spec/rails2/rails_app/app/views/test/needs.html.rb +7 -0
  43. data/spec/rails2/rails_app/app/views/test/needs_subclass.html.rb +5 -0
  44. data/spec/rails2/rails_app/app/views/test/protected_instance_variable.html.rb +5 -0
  45. data/spec/rails2/rails_app/app/views/test/render_default.html.rb +5 -0
  46. data/spec/rails2/rails_app/app/views/test/render_partial.html.rb +5 -0
  47. data/spec/rails2/rails_app/config/boot.rb +114 -0
  48. data/spec/rails2/rails_app/config/database.yml +16 -0
  49. data/spec/rails2/rails_app/config/environment.rb +42 -0
  50. data/spec/rails2/rails_app/config/environments/development.rb +17 -0
  51. data/spec/rails2/rails_app/config/environments/production.rb +28 -0
  52. data/spec/rails2/rails_app/config/environments/test.rb +28 -0
  53. data/spec/rails2/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  54. data/spec/rails2/rails_app/config/initializers/cookie_verification_secret.rb +7 -0
  55. data/spec/rails2/rails_app/config/initializers/inflections.rb +10 -0
  56. data/spec/rails2/rails_app/config/initializers/mime_types.rb +5 -0
  57. data/spec/rails2/rails_app/config/initializers/new_rails_defaults.rb +21 -0
  58. data/spec/rails2/rails_app/config/initializers/session_store.rb +15 -0
  59. data/spec/rails2/rails_app/config/locales/en.yml +5 -0
  60. data/spec/rails2/rails_app/config/routes.rb +43 -0
  61. data/spec/rails2/rails_app/db/development.sqlite3 +0 -0
  62. data/spec/rails2/rails_app/db/schema.rb +14 -0
  63. data/spec/rails2/rails_app/db/seeds.rb +7 -0
  64. data/spec/rails2/rails_app/doc/README_FOR_APP +2 -0
  65. data/spec/rails2/rails_app/log/development.log +76 -0
  66. data/spec/rails2/rails_app/log/production.log +0 -0
  67. data/spec/rails2/rails_app/log/server.log +0 -0
  68. data/spec/rails2/rails_app/log/test.log +4158 -0
  69. data/spec/rails2/rails_app/public/404.html +30 -0
  70. data/spec/rails2/rails_app/public/422.html +30 -0
  71. data/spec/rails2/rails_app/public/500.html +30 -0
  72. data/spec/rails2/rails_app/public/favicon.ico +0 -0
  73. data/spec/rails2/rails_app/public/images/rails.png +0 -0
  74. data/spec/rails2/rails_app/public/index.html +275 -0
  75. data/spec/rails2/rails_app/public/javascripts/application.js +2 -0
  76. data/spec/rails2/rails_app/public/javascripts/controls.js +963 -0
  77. data/spec/rails2/rails_app/public/javascripts/dragdrop.js +973 -0
  78. data/spec/rails2/rails_app/public/javascripts/effects.js +1128 -0
  79. data/spec/rails2/rails_app/public/javascripts/prototype.js +4320 -0
  80. data/spec/rails2/rails_app/public/robots.txt +5 -0
  81. data/spec/rails2/rails_app/script/about +4 -0
  82. data/spec/rails2/rails_app/script/console +3 -0
  83. data/spec/rails2/rails_app/script/dbconsole +3 -0
  84. data/spec/rails2/rails_app/script/destroy +3 -0
  85. data/spec/rails2/rails_app/script/generate +3 -0
  86. data/spec/rails2/rails_app/script/performance/benchmarker +3 -0
  87. data/spec/rails2/rails_app/script/performance/profiler +3 -0
  88. data/spec/rails2/rails_app/script/plugin +3 -0
  89. data/spec/rails2/rails_app/script/runner +3 -0
  90. data/spec/rails2/rails_app/script/server +3 -0
  91. data/spec/rails2/rails_app/spec/rails_helpers_spec.rb +255 -0
  92. data/spec/rails2/rails_app/spec/rails_spec_helper.rb +34 -0
  93. data/spec/rails2/rails_app/spec/rails_widget_spec.rb +83 -0
  94. data/spec/rails2/rails_app/spec/render_spec.rb +324 -0
  95. data/spec/rails2/rails_app/test/performance/browsing_test.rb +9 -0
  96. data/spec/rails2/rails_app/test/test_helper.rb +38 -0
  97. data/spec/rails2/rails_app/vendor/plugins/rails_xss/MIT-LICENSE +20 -0
  98. data/spec/rails2/rails_app/vendor/plugins/rails_xss/README.markdown +90 -0
  99. data/spec/rails2/rails_app/vendor/plugins/rails_xss/Rakefile +23 -0
  100. data/spec/rails2/rails_app/vendor/plugins/rails_xss/init.rb +7 -0
  101. data/spec/rails2/rails_app/vendor/plugins/rails_xss/lib/rails_xss.rb +3 -0
  102. data/spec/rails2/rails_app/vendor/plugins/rails_xss/lib/rails_xss/action_view.rb +87 -0
  103. data/spec/rails2/rails_app/vendor/plugins/rails_xss/lib/rails_xss/erubis.rb +33 -0
  104. data/spec/rails2/rails_app/vendor/plugins/rails_xss/lib/rails_xss/string_ext.rb +52 -0
  105. data/spec/rails2/rails_app/vendor/plugins/rails_xss/lib/tasks/rails_xss_tasks.rake +4 -0
  106. data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/active_record_helper_test.rb +74 -0
  107. data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/asset_tag_helper_test.rb +49 -0
  108. data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/caching_test.rb +43 -0
  109. data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/date_helper_test.rb +29 -0
  110. data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/deprecated_output_safety_test.rb +112 -0
  111. data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/erb_util_test.rb +36 -0
  112. data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/form_helper_test.rb +1447 -0
  113. data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/form_tag_helper_test.rb +354 -0
  114. data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/output_safety_test.rb +115 -0
  115. data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/rails_xss_test.rb +23 -0
  116. data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/test_helper.rb +5 -0
  117. data/spec/rails2/rails_app/vendor/plugins/rails_xss/test/text_helper_test.rb +17 -0
  118. data/spec/spec_helper.rb +2 -6
  119. metadata +348 -23
  120. data/lib/erector/errors.rb +0 -12
  121. data/lib/erector/extensions/hash.rb +0 -21
  122. data/lib/erector/extensions/object.rb +0 -18
  123. data/lib/erector/rails/rails_version.rb +0 -6
  124. data/rails/init.rb +0 -4
@@ -148,6 +148,17 @@ end
148
148
  end
149
149
  end
150
150
  end
151
+ })
152
+ end
153
+
154
+ it "escapes single quotes around ERb escapes" do
155
+ convert(".",
156
+ "<div value=\"don't <%= tase %> me, bro!\" />",
157
+ %{class Dummy < Erector::Widget
158
+ def content
159
+ div(:value => ('don\\\'t ' + tase + ' me, bro!'))
160
+ end
161
+ end
151
162
  })
152
163
  end
153
164
 
@@ -0,0 +1,114 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
+ require "erector/rails"
3
+ require "rails/version"
4
+
5
+ # backport mktmpdir so this test will work on Ruby 1.8.6
6
+ unless Dir.respond_to?(:mktmpdir)
7
+ def Dir.mktmpdir(prefix_suffix=nil, tmpdir=nil)
8
+ case prefix_suffix
9
+ when nil
10
+ prefix = "d"
11
+ suffix = ""
12
+ when String
13
+ prefix = prefix_suffix
14
+ suffix = ""
15
+ when Array
16
+ prefix = prefix_suffix[0]
17
+ suffix = prefix_suffix[1]
18
+ else
19
+ raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
20
+ end
21
+ tmpdir ||= Dir.tmpdir
22
+ t = Time.now.strftime("%Y%m%d")
23
+ n = nil
24
+ begin
25
+ path = "#{tmpdir}/#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
26
+ path << "-#{n}" if n
27
+ path << suffix
28
+ Dir.mkdir(path, 0700)
29
+ rescue Errno::EEXIST
30
+ n ||= 0
31
+ n += 1
32
+ retry
33
+ end
34
+
35
+ if block_given?
36
+ begin
37
+ yield path
38
+ ensure
39
+ FileUtils.remove_entry_secure path
40
+ end
41
+ else
42
+ path
43
+ end
44
+ end
45
+ end
46
+
47
+ # Note: this is *not* inside the rails_root since we're not testing
48
+ # Erector inside a rails app. We're testing that we can use the command-line
49
+ # converter tool on a newly generated scaffold app (like we brag about in the
50
+ # user guide).
51
+ #
52
+ module Erector
53
+ describe "the Rails version" do
54
+ it "should be #{Erector::Rails::RAILS_VERSION}" do
55
+ ::Rails::VERSION::STRING.should == Erector::Rails::RAILS_VERSION
56
+ end
57
+ end
58
+
59
+ describe "Erect in a Rails app" do
60
+ def run(cmd)
61
+ stderr_file = Dir.tmpdir + "/stderr.txt"
62
+ stdout = IO.popen(cmd + " 2>#{stderr_file}") do |pipe|
63
+ pipe.read
64
+ end
65
+ stderr = File.open(stderr_file) {|f| f.read}
66
+ FileUtils.rm_f(stderr_file)
67
+ if $?.exitstatus != 0
68
+ raise "Command #{cmd} failed\nDIR:\n #{Dir.getwd}\nSTDOUT:\n#{indent stdout}\nSTDERR:\n#{indent stderr}"
69
+ else
70
+ return stdout
71
+ end
72
+ end
73
+
74
+ def indent(s)
75
+ s.gsub(/^/, ' ')
76
+ end
77
+
78
+ it "works like we say it does in the user guide" do
79
+ erector_dir = File.expand_path("#{File.dirname(__FILE__)}/../..")
80
+
81
+ # We add the paths to our vendored copy of rails to the load paths, so
82
+ # that this spec can be run without having a version of Rails (which may
83
+ # not match the version we wish to test against) installed.
84
+ rails_libs_argument = "-I'#{RAILS_LOAD_PATHS.join("':'")}'"
85
+
86
+ Dir.mktmpdir do |app_dir|
87
+ run "ruby #{rails_libs_argument} '#{VENDOR_RAILS}/railties/bin/rails' '#{app_dir}'"
88
+
89
+ FileUtils.cp_r(VENDOR_RAILS, "#{app_dir}/vendor/rails")
90
+
91
+ FileUtils.mkdir_p(app_dir + "/vendor/gems")
92
+ FileUtils.cp_r(erector_dir, "#{app_dir}/vendor/gems/erector")
93
+
94
+ FileUtils.cd(app_dir) do
95
+ run "script/generate scaffold post title:string body:text published:boolean"
96
+
97
+ # The 'erector' binary would normally have been installed through rubygems,
98
+ # providing it with a wrapper script which requires rubygems. But here we
99
+ # run it directly, so we need to require rubygems explicitly before running
100
+ # the main script.
101
+ run "ruby #{rails_libs_argument} -I'#{erector_dir}/lib' " +
102
+ "-e \"require 'rubygems'; load '#{erector_dir}/bin/erector'\" app/views/posts"
103
+
104
+ FileUtils.rm_f("app/views/posts/*.erb")
105
+ run "rake --trace db:migrate"
106
+
107
+ # run "script/server" # todo: launch in background; use mechanize or something to crawl it; then kill it
108
+ # perhaps use open4?
109
+ # open http://localhost:3000/posts
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,12 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rails', '2.3.11'
4
+ gem 'sqlite3-ruby', :require => 'sqlite3'
5
+ gem "erector", :path => "../../.."
6
+ gem "i18n"
7
+
8
+ group :test do
9
+ gem 'rspec'
10
+ gem 'rr'
11
+ gem 'nokogiri'
12
+ end
@@ -0,0 +1,89 @@
1
+ PATH
2
+ remote: ../../..
3
+ specs:
4
+ erector (0.9.0.pre1)
5
+ treetop (>= 1.2.3)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ ParseTree (3.0.7)
11
+ RubyInline (>= 3.7.0)
12
+ sexp_processor (>= 3.0.0)
13
+ RubyInline (3.9.0)
14
+ ZenTest (~> 4.3)
15
+ ZenTest (4.5.0)
16
+ actionmailer (2.3.11)
17
+ actionpack (= 2.3.11)
18
+ actionpack (2.3.11)
19
+ activesupport (= 2.3.11)
20
+ rack (~> 1.1.0)
21
+ activerecord (2.3.11)
22
+ activesupport (= 2.3.11)
23
+ activeresource (2.3.11)
24
+ activesupport (= 2.3.11)
25
+ activesupport (2.3.11)
26
+ diff-lcs (1.1.2)
27
+ file-tail (1.0.6)
28
+ spruz (~> 0.2)
29
+ i18n (0.5.0)
30
+ nokogiri (1.5.0)
31
+ polyglot (0.3.1)
32
+ predicated (0.2.6)
33
+ rack (1.1.2)
34
+ rails (2.3.11)
35
+ actionmailer (= 2.3.11)
36
+ actionpack (= 2.3.11)
37
+ activerecord (= 2.3.11)
38
+ activeresource (= 2.3.11)
39
+ activesupport (= 2.3.11)
40
+ rake (>= 0.8.3)
41
+ rake (0.9.2)
42
+ rr (1.0.2)
43
+ rspec (2.6.0)
44
+ rspec-core (~> 2.6.0)
45
+ rspec-expectations (~> 2.6.0)
46
+ rspec-mocks (~> 2.6.0)
47
+ rspec-core (2.6.4)
48
+ rspec-expectations (2.6.0)
49
+ diff-lcs (~> 1.1.2)
50
+ rspec-mocks (2.6.0)
51
+ ruby2ruby (1.2.5)
52
+ ruby_parser (~> 2.0)
53
+ sexp_processor (~> 3.0)
54
+ ruby_parser (2.0.6)
55
+ sexp_processor (~> 3.0)
56
+ sexp_processor (3.0.5)
57
+ sourcify (0.5.0)
58
+ file-tail (>= 1.0.5)
59
+ ruby2ruby (>= 1.2.5)
60
+ ruby_parser (>= 2.0.5)
61
+ sexp_processor (>= 3.0.5)
62
+ spruz (0.2.11)
63
+ sqlite3 (1.3.3)
64
+ sqlite3-ruby (1.3.3)
65
+ sqlite3 (>= 1.3.3)
66
+ treetop (1.4.9)
67
+ polyglot (>= 0.3.1)
68
+ wrong (0.5.4)
69
+ ParseTree (~> 3.0)
70
+ diff-lcs (~> 1.1.2)
71
+ file-tail (~> 1.0)
72
+ predicated (>= 0.2.3)
73
+ ruby2ruby (~> 1.2)
74
+ ruby_parser (~> 2.0.4)
75
+ sexp_processor (~> 3.0)
76
+ sourcify (>= 0.3.0)
77
+
78
+ PLATFORMS
79
+ ruby
80
+
81
+ DEPENDENCIES
82
+ erector!
83
+ i18n
84
+ nokogiri
85
+ rails (= 2.3.11)
86
+ rr
87
+ rspec
88
+ sqlite3-ruby
89
+ wrong (>= 0.5.4)
@@ -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.