diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 07add258..f1147333 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -48,6 +48,9 @@ class ApplicationController < ActionController::Base '.jpg' => 'image/jpeg', '.pdf' => 'application/pdf', '.png' => 'image/png', + '.oga' => 'audio/ogg', + '.ogg' => 'audio/ogg', + '.ogv' => 'video/ogg', '.txt' => 'text/plain', '.tex' => 'text/plain', '.zip' => 'application/zip' @@ -59,6 +62,8 @@ class ApplicationController < ActionController::Base 'image/jpeg' => 'inline', 'application/pdf' => 'inline', 'image/png' => 'inline', + 'audio/ogg' => 'inline', + 'video/ogg' => 'inline', 'text/plain' => 'inline', 'application/zip' => 'attachment' } unless defined? DISPOSITION @@ -67,6 +72,7 @@ class ApplicationController < ActionController::Base original_options[:type] ||= (FILE_TYPES[File.extname(file_name)] or 'application/octet-stream') original_options[:disposition] ||= (DISPOSITION[original_options[:type]] or 'attachment') original_options[:stream] ||= false + original_options[:x_sendfile] = true if request.env.include?('HTTP_X_SENDFILE_TYPE') original_options end diff --git a/config/environment.rb b/config/environment.rb index bfe2cd27..bb0bef2f 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -7,7 +7,6 @@ rexml_versions = ['', File.dirname(__FILE__) + '/../vendor/plugins/rexml/lib/']. `ruby -r #{v + 'rexml/rexml'} -e 'p REXML::VERSION'`.split('.').collect {|n| n.to_i} } $:.unshift(File.dirname(__FILE__) + '/../vendor/plugins/rexml/lib') if (rexml_versions[0] <=> rexml_versions[1]) == -1 -#$:.unshift(File.dirname(__FILE__) + '/../vendor/plugins/rack/lib') require File.join(File.dirname(__FILE__), 'boot') require 'active_support/secure_random' @@ -60,3 +59,7 @@ require_dependency 'instiki_errors' #require 'jcode' require 'caching_stuff' + +#Additional Mime-types +mime_types = YAML.load_file(File.join(File.dirname(__FILE__), 'mime_types.yml')) +Rack::Mime::MIME_TYPES.merge!(mime_types) diff --git a/config/mime_types.yml b/config/mime_types.yml index 76ad41fe..3d498bf6 100644 --- a/config/mime_types.yml +++ b/config/mime_types.yml @@ -3,6 +3,9 @@ .gz: application/x-gzip .js: application/x-javascript .nb: application/mathematica +.oga: audio/ogg +.ogg: audio/ogg +.ogv: video/ogg .pdf: application/pdf .svg: application/svg+xml .tar: application/x-tar diff --git a/lib/chunks/wiki.rb b/lib/chunks/wiki.rb index 9fe9c860..277829fa 100644 --- a/lib/chunks/wiki.rb +++ b/lib/chunks/wiki.rb @@ -105,7 +105,7 @@ module WikiChunk unless defined? WIKI_LINK WIKI_LINK = /(":)?\[\[\s*([^\]\s][^\]]*?)\s*\]\]/ - LINK_TYPE_SEPARATION = Regexp.new('^(.+):((file)|(pic)|(delete))$', 0) + LINK_TYPE_SEPARATION = Regexp.new('^(.+):((file)|(pic)|(video)|(delete))$', 0) ALIAS_SEPARATION = Regexp.new('^(.+)\|(.+)$', 0) WEB_SEPARATION = Regexp.new('^(.+):(.+)$', 0) end diff --git a/lib/sanitizer.rb b/lib/sanitizer.rb index 10faa662..556dc4a6 100644 --- a/lib/sanitizer.rb +++ b/lib/sanitizer.rb @@ -14,7 +14,7 @@ module Sanitizer em fieldset font form h1 h2 h3 h4 h5 h6 hr i img input ins kbd label legend li map menu ol optgroup option p pre q s samp select small span strike strong sub sup table tbody td textarea tfoot th thead tr tt u - ul var] + ul var video] mathml_elements = %w[annotation annotation-xml maction math merror mfrac mfenced mi mmultiscripts mn mo mover mpadded mphantom mprescripts mroot @@ -29,7 +29,7 @@ module Sanitizer acceptable_attributes = %w[abbr accept accept-charset accesskey action align alt axis border cellpadding cellspacing char charoff charset - checked cite class clear cols colspan color compact coords datetime + checked cite class clear cols colspan color compact controls coords datetime dir disabled enctype for frame headers height href hreflang hspace id ismap label lang longdesc maxlength media method multiple name nohref noshade nowrap prompt readonly rel rev rows rowspan rules scope diff --git a/lib/url_generator.rb b/lib/url_generator.rb index 41717b0a..b7cac5f6 100644 --- a/lib/url_generator.rb +++ b/lib/url_generator.rb @@ -35,6 +35,8 @@ class AbstractUrlGenerator file_link(mode, name, text, web.address, known_page, description) when :pic pic_link(mode, name, text, web.address, known_page) + when :video + video_link(mode, name, text, web.address, known_page) when :delete delete_link(mode, name, web.address, known_page) else @@ -141,6 +143,31 @@ class UrlGenerator < AbstractUrlGenerator end end + def video_link(mode, name, text, web_address, known_vid) + href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file', + :id => name + case mode + when :export + if known_vid + %{} + else + text + end + when :publish + if known_vid + %{} + else + %{#{text}} + end + else + if known_vid + %{} + else + %{#{text}?} + end + end + end + def delete_link(mode, name, web_address, known_file) href = @controller.url_for :controller => 'file', :web => web_address, :action => 'delete', :id => name diff --git a/vendor/plugins/HTML5lib/lib/html5/sanitizer.rb b/vendor/plugins/HTML5lib/lib/html5/sanitizer.rb index 3055b7a8..6a9bf81f 100644 --- a/vendor/plugins/HTML5lib/lib/html5/sanitizer.rb +++ b/vendor/plugins/HTML5lib/lib/html5/sanitizer.rb @@ -24,7 +24,7 @@ module HTML5 em fieldset font form h1 h2 h3 h4 h5 h6 hr i img input ins kbd label legend li map menu ol optgroup option p pre q s samp select small span strike strong sub sup table tbody td textarea tfoot th thead tr tt u - ul var] + ul var video] MATHML_ELEMENTS = %w[annotation annotation-xml maction math merror mfrac mfenced mi mmultiscripts mn mo mover mpadded mphantom mprescripts mroot mrow @@ -39,7 +39,7 @@ module HTML5 ACCEPTABLE_ATTRIBUTES = %w[abbr accept accept-charset accesskey action align alt axis border cellpadding cellspacing char charoff charset - checked cite class clear cols colspan color compact coords datetime + checked cite class clear cols colspan color compact controls coords datetime dir disabled enctype for frame headers height href hreflang hspace id ismap label lang longdesc maxlength media method multiple name nohref noshade nowrap prompt readonly rel rev rows rowspan rules scope diff --git a/vendor/rails/actionmailer/CHANGELOG b/vendor/rails/actionmailer/CHANGELOG index 0749ff4d..7c6cba29 100644 --- a/vendor/rails/actionmailer/CHANGELOG +++ b/vendor/rails/actionmailer/CHANGELOG @@ -1,4 +1,4 @@ -*2.3.1 [RC2] (February 27th, 2009)* +*2.3.1 [RC2] (February ?, 2009)* * Fixed that ActionMailer should send correctly formatted Return-Path in MAIL FROM for SMTP #1842 [Matt Jones] diff --git a/vendor/rails/actionmailer/lib/action_mailer/part.rb b/vendor/rails/actionmailer/lib/action_mailer/part.rb index 977c0b2b..2bbb59cd 100644 --- a/vendor/rails/actionmailer/lib/action_mailer/part.rb +++ b/vendor/rails/actionmailer/lib/action_mailer/part.rb @@ -88,7 +88,10 @@ module ActionMailer part.parts << prt end - part.set_content_type(real_content_type, nil, ctype_attrs) if real_content_type =~ /multipart/ + if real_content_type =~ /multipart/ + ctype_attrs.delete 'charset' + part.set_content_type(real_content_type, nil, ctype_attrs) + end end headers.each { |k,v| part[k] = v } diff --git a/vendor/rails/actionmailer/test/mail_service_test.rb b/vendor/rails/actionmailer/test/mail_service_test.rb index 1e045317..26ba652f 100644 --- a/vendor/rails/actionmailer/test/mail_service_test.rb +++ b/vendor/rails/actionmailer/test/mail_service_test.rb @@ -330,6 +330,7 @@ class ActionMailerTest < Test::Unit::TestCase assert_equal "multipart/mixed", created.content_type assert_equal "multipart/alternative", created.parts.first.content_type assert_equal "bar", created.parts.first.header['foo'].to_s + assert_nil created.parts.first.charset assert_equal "text/plain", created.parts.first.parts.first.content_type assert_equal "text/html", created.parts.first.parts[1].content_type assert_equal "application/octet-stream", created.parts[1].content_type diff --git a/vendor/rails/actionpack/CHANGELOG b/vendor/rails/actionpack/CHANGELOG index 516f2814..809e90ff 100644 --- a/vendor/rails/actionpack/CHANGELOG +++ b/vendor/rails/actionpack/CHANGELOG @@ -1,4 +1,6 @@ -*2.3.1 [RC2] (February 27th, 2009)* +*2.3.1 [RC2] (February ?, 2009)* + +* Added ability to pass in :public => true to fresh_when, stale?, and expires_in to make the request proxy cachable #2095 [Gregg Pollack] * Fixed that passing a custom form builder would be forwarded to nested fields_for calls #2023 [Eloy Duran/Nate Wiger] diff --git a/vendor/rails/actionpack/lib/action_controller/base.rb b/vendor/rails/actionpack/lib/action_controller/base.rb index 5df94b28..564fdf67 100644 --- a/vendor/rails/actionpack/lib/action_controller/base.rb +++ b/vendor/rails/actionpack/lib/action_controller/base.rb @@ -1133,6 +1133,11 @@ module ActionController #:nodoc: # request is considered stale and should be generated from scratch. Otherwise, # it's fresh and we don't need to generate anything and a reply of "304 Not Modified" is sent. # + # Parameters: + # * :etag + # * :last_modified + # * :public By default the Cache-Control header is private, set this to true if you want your application to be cachable by other devices (proxy caches). + # # Example: # # def show @@ -1153,20 +1158,34 @@ module ActionController #:nodoc: # Sets the etag, last_modified, or both on the response and renders a # "304 Not Modified" response if the request is already fresh. # + # Parameters: + # * :etag + # * :last_modified + # * :public By default the Cache-Control header is private, set this to true if you want your application to be cachable by other devices (proxy caches). + # # Example: # # def show # @article = Article.find(params[:id]) - # fresh_when(:etag => @article, :last_modified => @article.created_at.utc) + # fresh_when(:etag => @article, :last_modified => @article.created_at.utc, :public => true) # end # # This will render the show template if the request isn't sending a matching etag or # If-Modified-Since header and just a "304 Not Modified" response if there's a match. + # def fresh_when(options) - options.assert_valid_keys(:etag, :last_modified) + options.assert_valid_keys(:etag, :last_modified, :public) response.etag = options[:etag] if options[:etag] response.last_modified = options[:last_modified] if options[:last_modified] + + if options[:public] + cache_control = response.headers["Cache-Control"].split(",").map {|k| k.strip } + cache_control.delete("private") + cache_control.delete("no-cache") + cache_control << "public" + response.headers["Cache-Control"] = cache_control.join(', ') + end if request.fresh?(response) head :not_modified @@ -1178,15 +1197,24 @@ module ActionController #:nodoc: # # Examples: # expires_in 20.minutes - # expires_in 3.hours, :private => false - # expires in 3.hours, 'max-stale' => 5.hours, :private => nil, :public => true + # expires_in 3.hours, :public => true + # expires in 3.hours, 'max-stale' => 5.hours, :public => true # # This method will overwrite an existing Cache-Control header. # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html for more possibilities. def expires_in(seconds, options = {}) #:doc: - cache_options = { 'max-age' => seconds, 'private' => true }.symbolize_keys.merge!(options.symbolize_keys) - cache_options.delete_if { |k,v| v.nil? or v == false } - cache_control = cache_options.map{ |k,v| v == true ? k.to_s : "#{k.to_s}=#{v.to_s}"} + cache_control = response.headers["Cache-Control"].split(",").map {|k| k.strip } + + cache_control << "max-age=#{seconds}" + if options[:public] + cache_control.delete("private") + cache_control.delete("no-cache") + cache_control << "public" + end + + # This allows for additional headers to be passed through like 'max-stale' => 5.hours + cache_control += options.symbolize_keys.reject{|k,v| k == :public || k == :private }.map{ |k,v| v == true ? k.to_s : "#{k.to_s}=#{v.to_s}"} + response.headers["Cache-Control"] = cache_control.join(', ') end diff --git a/vendor/rails/actionpack/lib/action_view/base.rb b/vendor/rails/actionpack/lib/action_view/base.rb index 65b20623..fe6053e5 100644 --- a/vendor/rails/actionpack/lib/action_view/base.rb +++ b/vendor/rails/actionpack/lib/action_view/base.rb @@ -183,12 +183,12 @@ module ActionView #:nodoc: cattr_accessor :debug_rjs # Specify whether templates should be cached. Otherwise the file we be read everytime it is accessed. - # Automaticaly reloading templates are not thread safe and should only be used in development mode. - @@cache_template_loading = false + # Automatically reloading templates are not thread safe and should only be used in development mode. + @@cache_template_loading = nil cattr_accessor :cache_template_loading def self.cache_template_loading? - ActionController::Base.allow_concurrency || cache_template_loading + ActionController::Base.allow_concurrency || (cache_template_loading.nil? ? !ActiveSupport::Dependencies.load? : cache_template_loading) end attr_internal :request diff --git a/vendor/rails/actionpack/test/controller/render_test.rb b/vendor/rails/actionpack/test/controller/render_test.rb index 70e5e62c..02ae8ac9 100644 --- a/vendor/rails/actionpack/test/controller/render_test.rb +++ b/vendor/rails/actionpack/test/controller/render_test.rb @@ -36,6 +36,39 @@ class TestController < ActionController::Base render :action => 'hello_world' end end + + def conditional_hello_with_public_header + if stale?(:last_modified => Time.now.utc.beginning_of_day, :etag => [:foo, 123], :public => true) + render :action => 'hello_world' + end + end + + def conditional_hello_with_public_header_and_expires_at + expires_in 1.minute + if stale?(:last_modified => Time.now.utc.beginning_of_day, :etag => [:foo, 123], :public => true) + render :action => 'hello_world' + end + end + + def conditional_hello_with_expires_in + expires_in 1.minute + render :action => 'hello_world' + end + + def conditional_hello_with_expires_in_with_public + expires_in 1.minute, :public => true + render :action => 'hello_world' + end + + def conditional_hello_with_expires_in_with_public_with_more_keys + expires_in 1.minute, :public => true, 'max-stale' => 5.hours + render :action => 'hello_world' + end + + def conditional_hello_with_expires_in_with_public_with_more_keys_old_syntax + expires_in 1.minute, :public => true, :private => nil, 'max-stale' => 5.hours + render :action => 'hello_world' + end def conditional_hello_with_bangs render :action => 'hello_world' @@ -1464,6 +1497,35 @@ class RenderTest < ActionController::TestCase end end +class ExpiresInRenderTest < ActionController::TestCase + tests TestController + + def setup + @request.host = "www.nextangle.com" + end + + def test_expires_in_header + get :conditional_hello_with_expires_in + assert_equal "max-age=60, private", @response.headers["Cache-Control"] + end + + def test_expires_in_header + get :conditional_hello_with_expires_in_with_public + assert_equal "max-age=60, public", @response.headers["Cache-Control"] + end + + def test_expires_in_header_with_additional_headers + get :conditional_hello_with_expires_in_with_public_with_more_keys + assert_equal "max-age=60, public, max-stale=18000", @response.headers["Cache-Control"] + end + + def test_expires_in_old_syntax + get :conditional_hello_with_expires_in_with_public_with_more_keys_old_syntax + assert_equal "max-age=60, public, max-stale=18000", @response.headers["Cache-Control"] + end +end + + class EtagRenderTest < ActionController::TestCase tests TestController @@ -1553,6 +1615,16 @@ class EtagRenderTest < ActionController::TestCase get :conditional_hello_with_bangs assert_response :not_modified end + + def test_etag_with_public_true_should_set_header + get :conditional_hello_with_public_header + assert_equal "public", @response.headers['Cache-Control'] + end + + def test_etag_with_public_true_should_set_header_and_retain_other_headers + get :conditional_hello_with_public_header_and_expires_at + assert_equal "max-age=60, public", @response.headers['Cache-Control'] + end protected def etag_for(text) diff --git a/vendor/rails/actionpack/test/template/render_test.rb b/vendor/rails/actionpack/test/template/render_test.rb index de7fa3de..b042eb3d 100644 --- a/vendor/rails/actionpack/test/template/render_test.rb +++ b/vendor/rails/actionpack/test/template/render_test.rb @@ -230,7 +230,7 @@ module RenderTestCases end end - def test_template_with_malformed_template_handler_is_reachable_trough_its_exact_filename + def test_template_with_malformed_template_handler_is_reachable_through_its_exact_filename assert_equal "Don't render me!", @view.render(:file => 'test/malformed/malformed.html.erb~') end diff --git a/vendor/rails/activerecord/CHANGELOG b/vendor/rails/activerecord/CHANGELOG index 231402c5..c521a3be 100644 --- a/vendor/rails/activerecord/CHANGELOG +++ b/vendor/rails/activerecord/CHANGELOG @@ -1,4 +1,4 @@ -*2.3.1 [RC2] (February 27th, 2009)* +*2.3.1 [RC2] (February ?, 2009)* * Added ActiveRecord::Base.each and ActiveRecord::Base.find_in_batches for batch processing [DHH/Jamis Buck] diff --git a/vendor/rails/activerecord/lib/active_record/base.rb b/vendor/rails/activerecord/lib/active_record/base.rb index 55ab1fac..206b4efa 100755 --- a/vendor/rails/activerecord/lib/active_record/base.rb +++ b/vendor/rails/activerecord/lib/active_record/base.rb @@ -1759,7 +1759,7 @@ module ActiveRecord #:nodoc: scope = scope(:find) if :auto == scope if scope && (scoped_group = scope[:group]) sql << " GROUP BY #{scoped_group}" - sql << " HAVING #{scoped_having}" if (scoped_having = scope[:having]) + sql << " HAVING #{scope[:having]}" if scope[:having] end end end diff --git a/vendor/rails/activerecord/lib/active_record/serializers/json_serializer.rb b/vendor/rails/activerecord/lib/active_record/serializers/json_serializer.rb index 419b45d4..1fd65ed0 100644 --- a/vendor/rails/activerecord/lib/active_record/serializers/json_serializer.rb +++ b/vendor/rails/activerecord/lib/active_record/serializers/json_serializer.rb @@ -8,6 +8,25 @@ module ActiveRecord #:nodoc: # Returns a JSON string representing the model. Some configuration is # available through +options+. # + # The option ActiveRecord::Base.include_root_in_json controls the + # top-level behavior of to_json. In a new Rails application, it is set to + # true in initializers/new_rails_defaults.rb. When it is true, + # to_json will emit a single root node named after the object's type. For example: + # + # konata = User.find(1) + # ActiveRecord::Base.include_root_in_json = true + # konata.to_json + # # => { "user": {"id": 1, "name": "Konata Izumi", "age": 16, + # "created_at": "2006/08/01", "awesome": true} } + # + # ActiveRecord::Base.include_root_in_json = false + # konata.to_json + # # => {"id": 1, "name": "Konata Izumi", "age": 16, + # "created_at": "2006/08/01", "awesome": true} + # + # The remainder of the examples in this section assume include_root_in_json is set to + # false. + # # Without any +options+, the returned JSON string will include all # the model's attributes. For example: # diff --git a/vendor/rails/activerecord/test/cases/base_test.rb b/vendor/rails/activerecord/test/cases/base_test.rb index 973bb567..eec16c04 100755 --- a/vendor/rails/activerecord/test/cases/base_test.rb +++ b/vendor/rails/activerecord/test/cases/base_test.rb @@ -1755,6 +1755,13 @@ class BasicsTest < ActiveRecord::TestCase end end + def test_scoped_find_with_group_and_having + developers = Developer.with_scope(:find => { :group => 'salary', :having => "SUM(salary) > 10000", :select => "SUM(salary) as salary" }) do + Developer.find(:all) + end + assert_equal 3, developers.size + end + def test_find_last last = Developer.find :last assert_equal last, Developer.find(:first, :order => 'id desc') diff --git a/vendor/rails/activeresource/CHANGELOG b/vendor/rails/activeresource/CHANGELOG index 8f6101ac..00ee2c24 100644 --- a/vendor/rails/activeresource/CHANGELOG +++ b/vendor/rails/activeresource/CHANGELOG @@ -1,4 +1,4 @@ -*2.3.1 [RC2] (February 27th, 2009)* +*2.3.1 [RC2] (February ?, 2009)* * Nothing new, just included in 2.3.1 diff --git a/vendor/rails/activesupport/CHANGELOG b/vendor/rails/activesupport/CHANGELOG index c0f24a10..2ac432e3 100644 --- a/vendor/rails/activesupport/CHANGELOG +++ b/vendor/rails/activesupport/CHANGELOG @@ -1,4 +1,4 @@ -*2.3.1 [RC2] (February 27th, 2009)* +*2.3.1 [RC2] (February ?, 2009)* * Vendorize i18n 0.1.3 gem (fixes issues with incompatible character encodings in Ruby 1.9) #2038 [Akira Matsuda] diff --git a/vendor/rails/railties/CHANGELOG b/vendor/rails/railties/CHANGELOG index 962869f9..2b852dae 100644 --- a/vendor/rails/railties/CHANGELOG +++ b/vendor/rails/railties/CHANGELOG @@ -1,4 +1,4 @@ -*2.3.1 [RC2] (February 27th, 2009)* +*2.3.1 [RC2] (February ?, 2009)* * Allow metal to live in plugins #2045 [Matthew Rudy] diff --git a/vendor/rails/railties/guides/files/stylesheets/main.css b/vendor/rails/railties/guides/files/stylesheets/main.css index f8302505..5061b130 100644 --- a/vendor/rails/railties/guides/files/stylesheets/main.css +++ b/vendor/rails/railties/guides/files/stylesheets/main.css @@ -1,138 +1,70 @@ /* Guides.rubyonrails.org */ /* Main.css */ /* Created January 30, 2009 */ -/* Modified January 31, 2009 +/* Modified February 8, 2009 --------------------------------------- */ /* General --------------------------------------- */ -.left { - float: left; - margin-right: 1em; -} -.right { - float: right; - margin-left: 1em; -} -.small { - font-size: smaller; -} -.large { - font-size: larger; -} -.hide { - display: none; -} +.left {float: left; margin-right: 1em;} +.right {float: right; margin-left: 1em;} +.small {font-size: smaller;} +.large {font-size: larger;} +.hide {display: none;} -li ul, li ol { - margin: 0 1.5em; -} -ul, ol { - margin: 0 1.5em 1.5em 1.5em; -} +li ul, li ol { margin:0 1.5em; } +ul, ol { margin: 0 1.5em 1.5em 1.5em; } -ul { - list-style-type: disc; -} -ol { - list-style-type: decimal; -} +ul { list-style-type: disc; } +ol { list-style-type: decimal; } -dl { - margin: 0 0 1.5em 0; -} -dl dt { - font-weight: bold; -} -dd { - margin-left: 1.5em; -} +dl { margin: 0 0 1.5em 0; } +dl dt { font-weight: bold; } +dd { margin-left: 1.5em;} + +pre,code { margin: 1.5em 0; white-space: pre; overflow: auto; } +pre,code,tt { font: 1em 'andale mono', 'lucida console', monospace; line-height: 1.5; } -pre,code { - margin: 1.5em 0; - white-space: pre; -} -pre,code { - font: 1em 'andale mono', 'lucida console', monospace; - line-height: 1.5; -} +abbr, acronym { border-bottom: 1px dotted #666; } +address { margin: 0 0 1.5em; font-style: italic; } +del { color:#666; } -abbr, acronym { - border-bottom: 1px dotted #666; -} -address { - margin: 0 0 1.5em; - font-style: italic; -} -del { - color: #666; -} +blockquote { margin: 1.5em; color: #666; font-style: italic; } +strong { font-weight: bold; } +em, dfn { font-style: italic; } +dfn { font-weight: bold; } +sup, sub { line-height: 0; } +p {margin: 0 0 1.5em;} -blockquote { - margin: 1.5em; - color: #666; - font-style: italic; -} -strong { - font-weight: bold; -} -em, dfn { - font-style: italic; -} -dfn { - font-weight: bold; -} -sup, sub { - line-height: 0; -} -p { - margin: 0 0 1.5em; -} +label { font-weight: bold; } +fieldset { padding:1.4em; margin: 0 0 1.5em 0; border: 1px solid #ccc; } +legend { font-weight: bold; font-size:1.2em; } -label { - font-weight: bold; -} -fieldset { - padding: 1.4em; - margin: 0 0 1.5em 0; - border: 1px solid #ccc; -} -legend { - font-weight: bold; - font-size: 1.2em; -} - -input.text, input.title, textarea, select { - margin: 0.5em 0em; - border: 1px solid #bbb; +input.text, input.title, +textarea, select { + margin:0.5em 0; + border:1px solid #bbb; } table { - margin: 1em 0; - border: 1px solid #ddd; - background: #f4f4f4; - border-spacing: 0; + margin: 0 0 1.5em; + border: 2px solid #CCC; + background: #FFF; + border-collapse: collapse; } - + table th, table td { - padding: 0.25em; - border-right: 1px dotted #e0e0e0; - border-bottom: 1px dotted #e0e0e0; -} - -table th:last-child, table td:last-child { - border-right: none; + padding: 0.25em 1em; + border: 1px solid #CCC; + border-collapse: collapse; } table th { - border-bottom: 1px solid #ddd; - background: #f0f0f0; - font-weight: bold; -} - -table tt { - padding: 0.1em; + border-bottom: 2px solid #CCC; + background: #EEE; + font-weight: bold; + padding: 0.5em 1em; } @@ -140,438 +72,358 @@ table tt { --------------------------------------- */ body { - text-align: center; - font-family: Helvetica, Arial, sans-serif; - font-size: 87.5%; - line-height: 1.5em; - background: #222; - color: #999; -} + text-align: center; + font-family: Helvetica, Arial, sans-serif; + font-size: 87.5%; + line-height: 1.5em; + background: #222; + color: #999; + } .wrapper { - text-align: left; - margin: 0 auto; - width: 69em; -} + text-align: left; + margin: 0 auto; + width: 69em; + } #topNav { - padding: 1em 0; - color: #565656; + padding: 1em 0; + color: #565656; } #header { - background: #c52f24 url(../../images/header_tile.gif) repeat-x; - color: #FFF; - padding: 1.5em 0; - position: relative; - z-index: 99; -} + background: #c52f24 url(../../images/header_tile.gif) repeat-x; + color: #FFF; + padding: 1.5em 0; + position: relative; + z-index: 99; + } #feature { - background: #d5e9f6 url(../../images/feature_tile.gif) repeat-x; - color: #333; - padding: 0.5em 0 1.5em; + background: #d5e9f6 url(../../images/feature_tile.gif) repeat-x; + color: #333; + padding: 0.5em 0 1.5em; } #container { - background: #FFF; - color: #333; - padding: 0.5em 0 1.5em 0; -} + background: #FFF; + color: #333; + padding: 0.5em 0 1.5em 0; + } #mainCol { - width: 45em; - margin-left: 2em; -} + width: 45em; + margin-left: 2em; + } #subCol { - position: absolute; - z-index: 0; - top: 0; - right: 0; - background: #FFF; - padding: 1em 1.5em 1em 1.25em; - width: 17em; - font-size: 0.9285em; - line-height: 1.3846em; -} - -#extraCol { - display: none; -} + position: absolute; + z-index: 0; + top: 0; + right: 0; + background: #FFF; + padding: 1em 1.5em 1em 1.25em; + width: 17em; + font-size: 0.9285em; + line-height: 1.3846em; + } + +#extraCol {display: none;} #footer { - padding: 2em 0; - background: url(../../images/footer_tile.gif) repeat-x; -} + padding: 2em 0; + background: url(../../images/footer_tile.gif) repeat-x; + } #footer .wrapper { - padding-left: 2em; - width: 67em; + padding-left: 2em; + width: 67em; } -#header .wrapper, #topNav .wrapper, #feature .wrapper { - padding-left: 1em; - width: 68em; -} -#feature .wrapper { - width: 45em; - padding-right: 23em; - position: relative; - z-index: 0; -} +#header .wrapper, #topNav .wrapper, #feature .wrapper {padding-left: 1em; width: 68em;} +#feature .wrapper {width: 45em; padding-right: 23em; position: relative; z-index: 0;} /* Links --------------------------------------- */ a, a:link, a:visited { - color: #ee3f3f; - text-decoration: underline; -} + color: #ee3f3f; + text-decoration: underline; + } -#mainCol a, #subCol a { - color: #980905; -} +#mainCol a, #subCol a, #feature a {color: #980905;} /* Navigation --------------------------------------- */ -.nav { - margin: 0; - padding: 0; -} -.nav li { - display: inline; - list-style: none; -} +.nav {margin: 0; padding: 0;} +.nav li {display: inline; list-style: none;} #header .nav { - float: right; - margin-top: 1.5em; - font-size: 1.2857em; + float: right; + margin-top: 1.5em; + font-size: 1.2857em; } -#header .nav li { - margin: 0 0 0 0.5em; -} -#header .nav a { - color: #FFF; - text-decoration: none; -} -#header .nav a:hover { - text-decoration: underline; -} +#header .nav li {margin: 0 0 0 0.5em;} +#header .nav a {color: #FFF; text-decoration: none;} +#header .nav a:hover {text-decoration: underline;} #header .nav .index { - padding: 0.5em 1.5em; - border-radius: 1em; - -webkit-border-radius: 1em; - -moz-border-radius: 1em; - background: #980905; - position: relative; + padding: 0.5em 1.5em; + border-radius: 1em; + -webkit-border-radius: 1em; + -moz-border-radius: 1em; + background: #980905; + position: relative; } #header .nav .index a { - background: #980905 url(../../images/nav_arrow.gif) no-repeat right top; - padding-right: 1em; - position: relative; - z-index: 15; - padding-bottom: 0.125em; -} -#header .nav .index:hover a, #header .nav .index a:hover { - background-position: right -81px; + background: #980905 url(../../images/nav_arrow.gif) no-repeat right top; + padding-right: 1em; + position: relative; + z-index: 15; + padding-bottom: 0.125em; } +#header .nav .index:hover a, #header .nav .index a:hover {background-position: right -81px;} #guides { - width: 27em; - display: block; - background: #980905; - border-radius: 1em; - -webkit-border-radius: 1em; - -moz-border-radius: 1em; - -webkit-box-shadow: 0.25em 0.25em 1em rgba(0,0,0,0.25); - -moz-box-shadow: rgba(0,0,0,0.25) 0.25em 0.25em 1em; - color: #f1938c; - padding: 1.5em 2em; - position: absolute; - z-index: 10; - top: -0.25em; - right: 0; - padding-top: 2em; + width: 27em; + display: block; + background: #980905; + border-radius: 1em; + -webkit-border-radius: 1em; + -moz-border-radius: 1em; + -webkit-box-shadow: 0.25em 0.25em 1em rgba(0,0,0,0.25); + -moz-box-shadow: rgba(0,0,0,0.25) 0.25em 0.25em 1em; + color: #f1938c; + padding: 1.5em 2em; + position: absolute; + z-index: 10; + top: -0.25em; + right: 0; + padding-top: 2em; } #guides dt, #guides dd { - font-weight: normal; - font-size: 0.722em; - margin: 0; - padding: 0; -} -#guides dt { - padding: 0; - margin: 0.5em 0 0; -} -#guides a { - color: #FFF; - background: none !important; -} -#guides .L, #guides .R { - float: left; - width: 50%; - margin: 0; - padding: 0; -} -#guides .R { - float: right; + font-weight: normal; + font-size: 0.722em; + margin: 0; + padding: 0; } +#guides dt {padding:0; margin: 0.5em 0 0;} +#guides a {color: #FFF; background: none !important;} +#guides .L, #guides .R {float: left; width: 50%; margin: 0; padding: 0;} +#guides .R {float: right;} #guides hr { - display: block; - border: none; - height: 1px; - color: #f1938c; - background: #f1938c; + display: block; + border: none; + height: 1px; + color: #f1938c; + background: #f1938c; } /* Headings --------------------------------------- */ h1 { - font-size: 2.5em; - line-height: 1em; - margin: 0.6em 0 .2em; - font-weight: bold; -} + font-size: 2.5em; + line-height: 1em; + margin: 0.6em 0 .2em; + font-weight: bold; + } h2 { - font-size: 2.1428em; - line-height: 1em; - margin: 0.7em 0 .2333em; - font-weight: bold; -} + font-size: 2.1428em; + line-height: 1em; + margin: 0.7em 0 .2333em; + font-weight: bold; + } h3 { - font-size: 1.7142em; - line-height: 1.286em; - margin: 0.875em 0 0.2916em; - font-weight: bold; -} - + font-size: 1.7142em; + line-height: 1.286em; + margin: 0.875em 0 0.2916em; + font-weight: bold; + } + h4 { - font-size: 1.2857em; - line-height: 1.2em; - margin: 1.6667em 0 .3887em; - font-weight: bold; -} + font-size: 1.2857em; + line-height: 1.2em; + margin: 1.6667em 0 .3887em; + font-weight: bold; + } h5 { - font-size: 1em; - line-height: 1.5em; - margin: 1em 0 .5em; - font-weight: bold; + font-size: 1em; + line-height: 1.5em; + margin: 1em 0 .5em; + font-weight: bold; } -h6 { - font-size: 1em; - line-height: 1.5em; - margin: 1em 0 .5em; - font-weight: normal; +h6 { + font-size: 1em; + line-height: 1.5em; + margin: 1em 0 .5em; + font-weight: normal; + } + +.section { + padding-bottom: 0.25em; + border-bottom: 1px solid #999; } /* Content --------------------------------------- */ .pic { - margin: 0 2em 2em 0; + margin: 0 2em 2em 0; } -#topNav strong { - color: #999; - margin-right: 0.5em; -} -#topNav strong a { - color: #FFF; -} +#topNav strong {color: #999; margin-right: 0.5em;} +#topNav strong a {color: #FFF;} #header h1 { - float: left; - background: url(../../images/ruby_guides_logo.gif) no-repeat; - width: 492px; - text-indent: -9999em; - margin: 0; - padding: 0; + float: left; + background: url(../../images/rails_guides_logo.gif) no-repeat; + width: 297px; + text-indent: -9999em; + margin: 0; + padding: 0; } #header h1 a { - text-decoration: none; - display: block; - height: 77px; + text-decoration: none; + display: block; + height: 77px; } #feature p { - font-size: 1.2857em; - margin-bottom: 0.75em; + font-size: 1.2857em; + margin-bottom: 0.75em; } -#feature ul { - margin-left: 0; -} +#feature ul {margin-left: 0;} #feature ul li { - list-style: none; - background: url(../../images/check_bullet.gif) no-repeat left 0.5em; - padding: 0.5em 1.75em 0.5em 1.75em; - font-size: 1.1428em; - font-weight: bold; + list-style: none; + background: url(../../images/check_bullet.gif) no-repeat left 0.5em; + padding: 0.5em 1.75em 0.5em 1.75em; + font-size: 1.1428em; + font-weight: bold; } #mainCol dd, #subCol dd { - padding: 0.25em 0 1em; - border-bottom: 1px solid #CCC; - margin-bottom: 1em; - margin-left: 0; - padding-left: 28px; + padding: 0.25em 0 1em; + border-bottom: 1px solid #CCC; + margin-bottom: 1em; + margin-left: 0; + /*padding-left: 28px;*/ + padding-left: 0; } #mainCol dt, #subCol dt { - font-size: 1.2857em; - padding: 0.125em 0 0.25em 28px; - margin-bottom: 0; - background: url(../../images/book_icon.gif) no-repeat left top; + font-size: 1.2857em; + padding: 0.125em 0 0.25em 0; + margin-bottom: 0; + /*background: url(../../images/book_icon.gif) no-repeat left top; + padding: 0.125em 0 0.25em 28px;*/ } #mainCol dd.ticket, #subCol dd.ticket { - background: #fff9d8 url(../../images/tab_yellow.gif) no-repeat left top; - border: none; - padding: 1.25em 1em 1.25em 48px; - margin-left: 0; - margin-top: 0.25em; + background: #fff9d8 url(../../images/tab_yellow.gif) no-repeat left top; + border: none; + padding: 1.25em 1em 1.25em 48px; + margin-left: 0; + margin-top: 0.25em; } #mainCol dd.warning, #subCol dd.warning { - background: #f9d9d8 url(../../images/tab_red.gif) no-repeat left top; - border: none; - padding: 1.25em 1.25em 1.25em 48px; - margin-left: 0; - margin-top: 0.25em; + background: #f9d9d8 url(../../images/tab_red.gif) no-repeat left top; + border: none; + padding: 1.25em 1.25em 1.25em 48px; + margin-left: 0; + margin-top: 0.25em; } -#subCol .chapters { - color: #980905; -} -#subCol .chapters a { - font-weight: bold; -} -#subCol .chapters ul a { - font-weight: normal; -} -#subCol .chapters li { - margin-bottom: 0.75em; -} -#subCol h3.chapter { - margin-top: 0.25em; -} -#subCol h3.chapter img { - vertical-align: text-bottom; -} -#subCol .chapters ul { - margin-left: 0; - margin-top: 0.5em; -} +#subCol .chapters {color: #980905;} +#subCol .chapters a {font-weight: bold;} +#subCol .chapters ul a {font-weight: normal;} +#subCol .chapters li {margin-bottom: 0.75em;} +#subCol h3.chapter {margin-top: 0.25em;} +#subCol h3.chapter img {vertical-align: text-bottom;} +#subCol .chapters ul {margin-left: 0; margin-top: 0.5em;} #subCol .chapters ul li { - list-style: none; - padding: 0 0 0 1em; - background: url(../../images/bullet.gif) no-repeat left 0.45em; - margin-left: 0; - font-size: 1em; - font-weight: normal; -} -#subCol .chapters p { - font-size: 1em; + list-style: none; + padding: 0 0 0 1em; + background: url(../../images/bullet.gif) no-repeat left 0.45em; + margin-left: 0; + font-size: 1em; + font-weight: normal; } tt { - font-family: monaco, "Bitstream Vera Sans Mono", "Courier New", courier, monospace; + font-family: monaco, "Bitstream Vera Sans Mono", "Courier New", courier, monospace; } -code, pre { - font-family: monaco, "Bitstream Vera Sans Mono", "Courier New", courier, monospace; - background: #EEE url(../../images/tab_grey.gif) no-repeat left top; - border: none; - padding: 0.25em 1em 0.5em 48px; - margin-left: 0; - margin-top: 0.25em; - display: block; - min-height: 45px; - overflow: auto; +div.code_container { + background: #EEE url(../../images/tab_grey.gif) no-repeat left top; + padding: 0.25em 1em 0.5em 48px; } -.info code, .info pre { - background-image: none; - background-color: #C5D9E6; - padding: 0.25em 1em; - min-height: 1px; +code { + font-family: monaco, "Bitstream Vera Sans Mono", "Courier New", courier, monospace; + border: none; + margin: 0.25em 0 1.5em 0; + display: block; } .note { - background: #fff9d8 url(../../images/tab_note.gif) no-repeat left top; - border: none; - padding: 1em 1em 0.25em 48px; - margin-left: 0; - margin-top: 0.25em; + background: #fff9d8 url(../../images/tab_note.gif) no-repeat left top; + border: none; + padding: 1em 1em 0.25em 48px; + margin: 0.25em 0 1.5em 0; } .info { - background: #d5e9f6 url(../../images/tab_info.gif) no-repeat left top; - border: none; - padding: 1em 1em 0.25em 48px; - margin-left: 0; - margin-top: 0.25em; + background: #d5e9f6 url(../../images/tab_info.gif) no-repeat left top; + border: none; + padding: 1em 1em 0.25em 48px; + margin: 0.25em 0 1.5em 0; } -.warning { - background: #f9d9d8 url(../../images/tab_red.gif) no-repeat left top; - border: none; - padding: 1em 1em 0.25em 48px; - margin-left: 0; - margin-top: 0.25em; -} - -.warning tt, .note tt, .info tt { - border: none; - background: none; - padding: 0; -} - -em.highlight { - background: #fffcdb; - padding: 0 0.25em; -} +.note tt, .info tt {border:none; background: none; padding: 0;} #mainCol ul li { - list-style: none; - background: url(../../images/grey_bullet.gif) no-repeat left 0.5em; - padding-left: 1em; - margin-left: 0; + list-style:none; + background: url(../../images/grey_bullet.gif) no-repeat left 0.5em; + padding-left: 1em; + margin-left: 0; } +#subCol .content { + font-size: 0.7857em; + line-height: 1.5em; +} + +#subCol .content li { + font-weight: normal; + background: none; + padding: 0 0 1em; + font-size: 1.1667em; +} + /* Clearing --------------------------------------- */ .clearfix:after { - content: "."; - display: block; - height: 0; - clear: both; + content: "."; + display: block; + height: 0; + clear: both; visibility: hidden; } -.clearfix { - display: inline-block; -} -* html .clearfix { - height: 1%; -} -.clearfix { - display: block; -} -.clear { - clear: both; -} +.clearfix {display: inline-block;} +* html .clearfix {height: 1%;} +.clearfix {display: block;} +.clear { clear:both; } \ No newline at end of file diff --git a/vendor/rails/railties/guides/images/rails_guides_logo.gif b/vendor/rails/railties/guides/images/rails_guides_logo.gif new file mode 100644 index 00000000..a24683a3 Binary files /dev/null and b/vendor/rails/railties/guides/images/rails_guides_logo.gif differ diff --git a/vendor/rails/railties/guides/images/ruby_guides_logo.gif b/vendor/rails/railties/guides/images/ruby_guides_logo.gif deleted file mode 100644 index a241fad5..00000000 Binary files a/vendor/rails/railties/guides/images/ruby_guides_logo.gif and /dev/null differ diff --git a/vendor/rails/railties/guides/images/ruby_on_rails_by_mike_rundle2.gif b/vendor/rails/railties/guides/images/ruby_on_rails_by_mike_rundle2.gif deleted file mode 100644 index 98ffefaf..00000000 Binary files a/vendor/rails/railties/guides/images/ruby_on_rails_by_mike_rundle2.gif and /dev/null differ diff --git a/vendor/rails/railties/guides/images/tab_grey.gif b/vendor/rails/railties/guides/images/tab_grey.gif index 2174c8ff..e9680b71 100644 Binary files a/vendor/rails/railties/guides/images/tab_grey.gif and b/vendor/rails/railties/guides/images/tab_grey.gif differ diff --git a/vendor/rails/railties/guides/images/tab_info.gif b/vendor/rails/railties/guides/images/tab_info.gif index ce7005f5..458fea9a 100644 Binary files a/vendor/rails/railties/guides/images/tab_info.gif and b/vendor/rails/railties/guides/images/tab_info.gif differ diff --git a/vendor/rails/railties/guides/images/tab_note.gif b/vendor/rails/railties/guides/images/tab_note.gif index 8e3036a0..1d5c171e 100644 Binary files a/vendor/rails/railties/guides/images/tab_note.gif and b/vendor/rails/railties/guides/images/tab_note.gif differ diff --git a/vendor/rails/railties/guides/images/tab_red.gif b/vendor/rails/railties/guides/images/tab_red.gif index d79998b9..daf140b5 100644 Binary files a/vendor/rails/railties/guides/images/tab_red.gif and b/vendor/rails/railties/guides/images/tab_red.gif differ diff --git a/vendor/rails/railties/guides/images/tab_yellow.gif b/vendor/rails/railties/guides/images/tab_yellow.gif index f9c46022..dc961c99 100644 Binary files a/vendor/rails/railties/guides/images/tab_yellow.gif and b/vendor/rails/railties/guides/images/tab_yellow.gif differ diff --git a/vendor/rails/railties/guides/rails_guides/generator.rb b/vendor/rails/railties/guides/rails_guides/generator.rb index 41d22e37..18fdb818 100644 --- a/vendor/rails/railties/guides/rails_guides/generator.rb +++ b/vendor/rails/railties/guides/rails_guides/generator.rb @@ -1,3 +1,5 @@ +require 'set' + module RailsGuides class Generator attr_reader :output, :view_path, :view, :guides_dir @@ -55,6 +57,7 @@ module RailsGuides result = view.render(:layout => 'layout', :text => textile(body)) f.write result + warn_about_broken_links(result) end end end @@ -106,9 +109,46 @@ module RailsGuides end def textile(body) - t = RedCloth.new(body) - t.hard_breaks = false - t.to_html(:notestuff, :plusplus, :code, :tip) + # If the issue with nontextile is fixed just remove the wrapper. + with_workaround_for_nontextile(body) do |body| + t = RedCloth.new(body) + t.hard_breaks = false + t.to_html(:notestuff, :plusplus, :code, :tip) + end + end + + # For some reason the notextile tag does not always turn off textile. See + # LH ticket of the security guide (#7). As a temporary workaround we deal + # with code blocks by hand. + def with_workaround_for_nontextile(body) + code_blocks = [] + body.gsub!(%r{<(yaml|shell|ruby|erb|html|sql|plain)>(.*?)}m) do |m| + es = ERB::Util.h($2) + css_class = ['erb', 'shell'].include?($1) ? 'html' : $1 + code_blocks << %{
#{es}
} + "dirty_workaround_for_nontextile_#{code_blocks.size - 1}" + end + + body = yield body + + body.gsub(%r{

dirty_workaround_for_nontextile_(\d+)

}) do |_| + code_blocks[$1.to_i] + end + end + + def warn_about_broken_links(html) + # Textile generates headers with IDs computed from titles. + anchors = Set.new(html.scan(/(.*?)\<\/\1\>/m) do |m| + body.gsub!(%r{<(yaml|shell|ruby|erb|html|sql|plain)>(.*?)}m) do |m| es = ERB::Util.h($2) css_class = ['erb', 'shell'].include?($1) ? 'html' : $1 - "#{es}\n" + %{
#{es}
} end end end diff --git a/vendor/rails/railties/guides/source/2_3_release_notes.textile b/vendor/rails/railties/guides/source/2_3_release_notes.textile index 4734e326..c58cbc0b 100644 --- a/vendor/rails/railties/guides/source/2_3_release_notes.textile +++ b/vendor/rails/railties/guides/source/2_3_release_notes.textile @@ -1,5 +1,7 @@ h2. Ruby on Rails 2.3 Release Notes +NOTE: These release notes refer to RC2 of Rails 2.3. This is a release candidate, and not the final version of Rails 2.3. It's intended to be a stable testing release, and we urge you to test your own applications and report any issues to the "Rails Lighthouse":http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/overview. + Rails 2.3 delivers a variety of new and improved features, including pervasive Rack integration, refreshed support for Rails Engines, nested transactions for Active Record, dynamic and default scopes, unified rendering, more efficient routing, application templates, and quiet backtraces. This list covers the major upgrades, but doesn't include every little bug fix and change. If you want to see everything, check out the "list of commits":http://github.com/rails/rails/commits/master in the main Rails repository on GitHub or review the +CHANGELOG+ files for the individual Rails components. endprologue. @@ -136,7 +138,7 @@ Customer.find_in_batches(:conditions => {:active => true}) do |customer_group| end -You can pass most of the +find+ options into +find_in_batches+. However, you cannot specify the order that records will be returned in (they will always be returned in ascending order of primary key, which must be an integer), or use the +:limit+ option. Instead, use the +:batch_size: option, which defaults to 1000, to set the number of records that will be returned in each batch. +You can pass most of the +find+ options into +find_in_batches+. However, you cannot specify the order that records will be returned in (they will always be returned in ascending order of primary key, which must be an integer), or use the +:limit+ option. Instead, use the +:batch_size+ option, which defaults to 1000, to set the number of records that will be returned in each batch. The new +each+ method provides a wrapper around +find_in_batches+ that returns individual records, with the find itself being done in batches (of 1000 by default): @@ -146,7 +148,11 @@ Customer.each do |customer| end -Note that you should only use this record for batch processing: for small numbers of records (less than 1000), you should just use the regular find methods with your own loop. +Note that you should only use this method for batch processing: for small numbers of records (less than 1000), you should just use the regular find methods with your own loop. + +* More Information: + - "Rails 2.3: Batch Finding":http://afreshcup.com/2009/02/23/rails-23-batch-finding/ + - "What's New in Edge Rails: Batched Find":http://ryandaigle.com/articles/2009/2/23/what-s-new-in-edge-rails-batched-find h4. Multiple Conditions for Callbacks @@ -313,6 +319,8 @@ h4. Other Action Controller Changes * Cookie sessions now have persistent session identifiers, with API compatibility with the server-side stores. * You can now use symbols for the +:type+ option of +send_file+ and +send_data+, like this: +send_file("fabulous.png", :type => :png)+. * The +:only+ and +:except+ options for +map.resources+ are no longer inherited by nested resources. +* The bundled memcached client has been updated to version 1.6.4.99. +* The +expires_in+, +stale?+, and +fresh_when+ methods now accept a +:public+ option to make them work well with proxy caching. h3. Action View @@ -431,6 +439,18 @@ returns +h4. A Note About Template Loading + +Rails 2.3 includes the ability to enable or disable cached templates for any particular environment. Cached templates give you a speed boost because they don't check for a new template file when they're rendered - but they also mean that you can't replace a template "on the fly" without restarting the server. + +In most cases, you'll want template caching to be turned on in production, which you can do by making a setting in your +production.rb+ file: + + +config.action_view.cache_template_loading = true + + +This line will be generated for you by default in a new Rails 2.3 application. If you've upgraded from an older version of Rails, Rails will default to caching templates in production and test but not in development. + h4. Other Action View Changes * Token generation for CSRF protection has been simplified; now Rails uses a simple random string generated by +ActiveSupport::SecureRandom+ rather than mucking around with session IDs. @@ -481,7 +501,7 @@ In addition to the Rack changes covered above, Railties (the core code of Rails h4. Rails Metal -Rails Metal is a new mechanism that provides superfast endpoints inside of your Rails applications. Metal classes bypass routing and Action Controller to give you raw speed (at the cost of all the things in Action Controller, of course). This builds on all of the recent foundation work to make Rails a Rack application with an exposed middleware stack. +Rails Metal is a new mechanism that provides superfast endpoints inside of your Rails applications. Metal classes bypass routing and Action Controller to give you raw speed (at the cost of all the things in Action Controller, of course). This builds on all of the recent foundation work to make Rails a Rack application with an exposed middleware stack. Metal endpoints can be loaded from your application or from plugins. * More Information: ** "Introducing Rails Metal":http://weblog.rubyonrails.org/2008/12/17/introducing-rails-metal @@ -538,6 +558,7 @@ A few pieces of older code are deprecated in this release: * +formatted_polymorphic_url+ is deprecated. Use +polymorphic_url+ with +:format+ instead. * The +:http_only+ option in +ActionController::Response#set_cookie+ has been renamed to +:httponly+. * The +:connector+ and +:skip_last_comma+ options of +to_sentence+ have been replaced by +:words_connnector+, +:two_words_connector+, and +:last_word_connector+ options. +* Posting a multipart form with an empty +file_field+ control used to submit an empty string to the controller. Now it submits a nil, due to differences between Rack's multipart parser and the old Rails one. h3. Credits diff --git a/vendor/rails/railties/guides/source/active_record_querying.textile b/vendor/rails/railties/guides/source/active_record_querying.textile index 5da15bbb..03e1b264 100644 --- a/vendor/rails/railties/guides/source/active_record_querying.textile +++ b/vendor/rails/railties/guides/source/active_record_querying.textile @@ -314,7 +314,7 @@ This will find all clients created yesterday by using a +BETWEEN+ SQL statement: SELECT * FROM clients WHERE (clients.created_at BETWEEN '2008-12-21 00:00:00' AND '2008-12-22 00:00:00') -This demonstrates a shorter syntax for the examples in "Array Conditions":#array-conditions +This demonstrates a shorter syntax for the examples in "Array Conditions":#arrayconditions h5. Subset conditions @@ -376,7 +376,7 @@ By default, Model.find selects all the fields from the result set using To select only a subset of fields from the result set, you can specify the subset via +:select+ option on the +find+. -NOTE: If the +:select+ option is used, all the returning objects will be "read only":#read-only objects. +NOTE: If the +:select+ option is used, all the returning objects will be "read only":#readonlyobjects.
diff --git a/vendor/rails/railties/guides/source/association_basics.textile b/vendor/rails/railties/guides/source/association_basics.textile index e82f32d3..3c03c825 100644 --- a/vendor/rails/railties/guides/source/association_basics.textile +++ b/vendor/rails/railties/guides/source/association_basics.textile @@ -37,7 +37,7 @@ end @customer.destroy -With Active Record associations, we can streamline these - and other - operations by declaratively telling Rails that there is a connection between the two models. Here's the revised code for setting up customers and orders: +With Active Record associations, we can streamline these -- and other -- operations by declaratively telling Rails that there is a connection between the two models. Here's the revised code for setting up customers and orders: class Customer < ActiveRecord::Base @@ -61,7 +61,7 @@ Deleting a customer and all of its orders is _much_ easier: @customer.destroy -To learn more about the different types of associations, read the next section of this Guide. That's followed by some tips and tricks for working with associations, and then by a complete reference to the methods and options for associations in Rails. +To learn more about the different types of associations, read the next section of this guide. That's followed by some tips and tricks for working with associations, and then by a complete reference to the methods and options for associations in Rails. h3. The Types of Associations @@ -76,7 +76,7 @@ In Rails, an _association_ is a connection between two Active Record models. Ass In the remainder of this guide, you'll learn how to declare and use the various forms of associations. But first, a quick introduction to the situations where each association type is appropriate. -h4. The belongs_to Association +h4. The +belongs_to+ association A +belongs_to+ association sets up a one-to-one connection with another model, such that each instance of the declaring model "belongs to" one instance of the other model. For example, if your application includes customers and orders, and each order can be assigned to exactly one customer, you'd declare the order model this way: @@ -88,7 +88,7 @@ end !images/belongs_to.png(belongs_to Association Diagram)! -h4. The has_one Association +h4. The +has_one+ association A +has_one+ association also sets up a one-to-one connection with another model, but with somewhat different semantics (and consequences). This association indicates that each instance of a model contains or possesses one instance of another model. For example, if each supplier in your application has only one account, you'd declare the supplier model like this: @@ -100,7 +100,7 @@ end !images/has_one.png(has_one Association Diagram)! -h4. The has_many Association +h4. The +has_many+ association A +has_many+ association indicates a one-to-many connection with another model. You'll often find this association on the "other side" of a +belongs_to+ association. This association indicates that each instance of the model has zero or more instances of another model. For example, in an application containing customers and orders, the customer model could be declared like this: @@ -114,7 +114,7 @@ NOTE: The name of the other model is pluralized when declaring a +has_many+ asso !images/has_many.png(has_many Association Diagram)! -h4. The has_many :through Association +h4. The +has_many :through+ association A +has_many :through+ association is often used to set up a many-to-many connection with another model. This association indicates that the declaring model can be matched with zero or more instances of another model by proceeding _through_ a third model. For example, consider a medical practice where patients make appointments to see physicians. The relevant association declarations could look like this: @@ -155,7 +155,7 @@ class Paragraph < ActiveRecord::Base end -h4. The has_one :through Association +h4. The +has_one :through+ association A +has_one :through+ association sets up a one-to-one connection with another model. This association indicates that the declaring model can be matched with one instance of another model by proceeding _through_ a third model. For example, if each supplier has one account, and each account is associated with one account history, then the customer model could look like this: @@ -177,7 +177,7 @@ end !images/has_one_through.png(has_one :through Association Diagram)! -h4. The has_and_belongs_to_many Association +h4. The +has_and_belongs_to_many+ association A +has_and_belongs_to_many+ association creates a direct many-to-many connection with another model, with no intervening model. For example, if your application includes assemblies and parts, with each assembly having many parts and each part appearing in many assemblies, you could declare the models this way: @@ -193,7 +193,7 @@ end !images/habtm.png(has_and_belongs_to_many Association Diagram)! -h4. Choosing Between belongs_to and has_one +h4. Choosing between +belongs_to+ and +has_one+ If you want to set up a 1–1 relationship between two models, you'll need to add +belongs_to+ to one, and +has_one+ to the other. How do you know which is which? @@ -235,7 +235,7 @@ end NOTE: Using +t.integer :supplier_id+ makes the foreign key naming obvious and explicit. In current versions of Rails, you can abstract away this implementation detail by using +t.references :supplier+ instead. -h4. Choosing Between has_many :through and has_and_belongs_to_many +h4. Choosing between +has_many :through+ and +has_and_belongs_to_many+ Rails offers two different ways to declare a many-to-many relationship between models. The simpler way is to use +has_and_belongs_to_many+, which allows you to make the association directly: @@ -272,7 +272,7 @@ The simplest rule of thumb is that you should set up a +has_many :through+ relat You should use +has_many :through+ if you need validations, callbacks, or extra attributes on the join model. -h4. Polymorphic Associations +h4. Polymorphic associations A slightly more advanced twist on associations is the _polymorphic association_. With polymorphic associations, a model can belong to more than one other model, on a single association. For example, you might have a picture model that belongs to either an employee model or a product model. Here's how this could be declared: @@ -319,7 +319,7 @@ This migration can be simplified by using the +t.references+ form: class CreatePictures < ActiveRecord::Migration def self.up create_table :pictures do |t| - t.string :name + t.string :name t.references :imageable, :polymorphic => true t.timestamps end @@ -333,7 +333,7 @@ end !images/polymorphic.png(Polymorphic Association Diagram)! -h4. Self Joins +h4. Self joins In designing a data model, you will sometimes find a model that should have a relation to itself. For example, you may want to store all employees in a single database model, but be able to trace relationships such as between manager and subordinates. This situation can be modeled with self-joining associations: @@ -356,7 +356,7 @@ Here are a few things you should know to make efficient use of Active Record ass * Updating the schema * Controlling association scope -h4. Controlling Caching +h4. Controlling caching All of the association methods are built around caching, which keeps the result of the most recent query available for further operations. The cache is even shared across methods. For example: @@ -375,15 +375,15 @@ customer.orders(true).empty? # discards the cached copy of orders # and goes back to the database -h4. Avoiding Name Collisions +h4. Avoiding name collisions You are not free to use just any name for your associations. Because creating an association adds a method with that name to the model, it is a bad idea to give an association a name that is already used for an instance method of +ActiveRecord::Base+. The association method would override the base method and break things. For instance, +attributes+ or +connection+ are bad names for associations. -h4. Updating the Schema +h4. Updating the schema Associations are extremely useful, but they are not magic. You are responsible for maintaining your database schema to match your associations. In practice, this means two things, depending on what sort of associations you are creating. For +belongs_to+ associations you need to create foreign keys, and for +has_and_belongs_to_many+ associations you need to create the appropriate join table. -h5. Creating Foreign Keys for belongs_to Associations +h5. Creating foreign Keys for +belongs_to+ associations When you declare a +belongs_to+ association, you need to create foreign keys as appropriate. For example, consider this model: @@ -399,9 +399,9 @@ This declaration needs to be backed up by the proper foreign key declaration on class CreateOrders < ActiveRecord::Migration def self.up create_table :orders do |t| - t.datetime :order_date - t.string :order_number - t.integer :customer_id + t.datetime :order_date + t.string :order_number + t.integer :customer_id end end @@ -413,7 +413,7 @@ end If you create an association some time after you build the underlying model, you need to remember to create an +add_column+ migration to provide the necessary foreign key. -h5. Creating Join Tables for has_and_belongs_to_many Associations +h5. Creating join tables for +has_and_belongs_to_many+ associations If you create a +has_and_belongs_to_many+ association, you need to explicitly create the joining table. Unless the name of the join table is explicitly specified by using the +:join_table+ option, Active Record creates the name by using the lexical order of the class names. So a join between customer and order models will give the default join table name of "customers_orders" because "c" outranks "o" in lexical ordering. @@ -448,7 +448,9 @@ class CreateAssemblyPartJoinTable < ActiveRecord::Migration end -h4. Controlling Association Scope +We pass +:id => false+ to +create_table+ because that table does not represent a model. That's required for the association to work properly. If you observe any strange behaviour in a +has_and_belongs_to_many+ association like mangled models IDs, or exceptions about conflicting IDs chances are you forgot that bit. + +h4. Controlling association scope By default, associations look for objects only within the current module's scope. This can be important when you declare Active Record models within a module. For example: @@ -484,7 +486,7 @@ module MyApplication end -To associate a model with a model in a different scope, you must specify the complete class name in your association declaration: +To associate a model with a model in a different namespace, you must specify the complete class name in your association declaration: module MyApplication @@ -508,17 +510,16 @@ h3. Detailed Association Reference The following sections give the details of each type of association, including the methods that they add and the options that you can use when declaring an association. -h4. belongs_to Association Reference +h4. +belongs_to+ association reference The +belongs_to+ association creates a one-to-one match with another model. In database terms, this association says that this class contains the foreign key. If the other class contains the foreign key, then you should use +has_one+ instead. -h5. Methods Added by belongs_to +h5. Methods added by +belongs_to+ -When you declare a +belongs_to+ association, the declaring class automatically gains five methods related to the association: +When you declare a +belongs_to+ association, the declaring class automatically gains four methods related to the association: * association(force_reload = false) * association=(associate) -* association.nil? * build_association(attributes = {}) * create_association(attributes = {}) @@ -535,7 +536,6 @@ Each instance of the order model will have these methods: customer customer= -customer.nil? build_customer create_customer @@ -558,23 +558,13 @@ The association= method assigns an associated object to this o @order.customer = @customer -h6. _association_.nil? - -The association.nil? method returns +true+ if there is no associated object. - - -if @order.customer.nil? - @msg = "No customer found for this order" -end - - h6. build_association(attributes = {}) The build_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through this object's foreign key will be set, but the associated object will _not_ yet be saved. -@customer = @order.build_customer({:customer_number => 123, - :customer_name => "John Doe"}) +@customer = @order.build_customer(:customer_number => 123, + :customer_name => "John Doe") h6. create_association(attributes = {}) @@ -582,11 +572,12 @@ h6. create_association(attributes = {}) The create_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through this object's foreign key will be set. In addition, the associated object _will_ be saved (assuming that it passes any validations). -@customer = @order.create_customer({:customer_number => 123, - :customer_name => "John Doe"}) +@customer = @order.create_customer(:customer_number => 123, + :customer_name => "John Doe") -h5. Options for belongs_to + +h5. Options for +belongs_to+ In many situations, you can use the default behavior of +belongs_to+ without any customization. But despite Rails' emphasis of convention over customization, you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a +belongs_to+ association. For example, an association with several options might look like this: @@ -611,11 +602,11 @@ The +belongs_to+ association supports these options: * +:select+ * +:validate+ -h6. :autosave +h6. +:autosave+ If you set the +:autosave+ option to +true+, Rails will save any loaded members and destroy members that are marked for destruction whenever you save the parent object. -h6. :class_name +h6. +:class_name+ If the name of the other model cannot be derived from the association name, you can use the +:class_name+ option to supply the model name. For example, if an order belongs to a customer, but the actual name of the model containing customers is +Patron+, you'd set things up this way: @@ -625,7 +616,7 @@ class Order < ActiveRecord::Base end -h6. :conditions +h6. +:conditions+ The +:conditions+ option lets you specify the conditions that the associated object must meet (in the syntax used by a SQL +WHERE+ clause). @@ -635,7 +626,7 @@ class Order < ActiveRecord::Base end -h6. :counter_cache +h6. +:counter_cache+ The +:counter_cache+ option can be used to make finding the number of belonging objects more efficient. Consider these models: @@ -659,7 +650,7 @@ class Customer < ActiveRecord::Base end -With this declaration, Rails will keep the cache value up to date, and then return that value in response to the +.size+ method. +With this declaration, Rails will keep the cache value up to date, and then return that value in response to the +size+ method. Although the +:counter_cache+ option is specified on the model that includes the +belongs_to+ declaration, the actual column must be added to the _associated_ model. In the case above, you would need to add a column named +orders_count+ to the +Customer+ model. You can override the default column name if you need to: @@ -674,13 +665,13 @@ end Counter cache columns are added to the containing model's list of read-only attributes through +attr_readonly+. -h6. :dependent +h6. +:dependent+ -If you set the +:dependent+ option to +:destroy+, then deleting this object will call the destroy method on the associated object to delete that object. If you set the +:dependent+ option to +:delete+, then deleting this object will delete the associated object _without_ calling its +destroy+ method. +If you set the +:dependent+ option to +:destroy+, then deleting this object will call the +destroy+ method on the associated object to delete that object. If you set the +:dependent+ option to +:delete+, then deleting this object will delete the associated object _without_ calling its +destroy+ method. WARNING: You should not specify this option on a +belongs_to+ association that is connected with a +has_many+ association on the other class. Doing so can lead to orphaned records in your database. -h6. :foreign_key +h6. +:foreign_key+ By convention, Rails guesses that the column used to hold the foreign key on this model is the name of the association with the suffix +_id+ added. The +:foreign_key+ option lets you set the name of the foreign key directly: @@ -693,7 +684,7 @@ end TIP: In any case, Rails will not create foreign key columns for you. You need to explicitly define them as part of your migrations. -h6. :include +h6. +:include+ You can use the +:include+ option to specify second-order associations that should be eager-loaded when this association is used. For example, consider these models: @@ -731,39 +722,48 @@ end NOTE: There's no need to use +:include+ for immediate associations - that is, if you have +Order belongs_to :customer+, then the customer is eager-loaded automatically when it's needed. -h6. :polymorphic +h6. +:polymorphic+ -Passing +true+ to the +:polymorphic+ option indicates that this is a polymorphic association. Polymorphic associations were discussed in detail earlier in this guide. +Passing +true+ to the +:polymorphic+ option indicates that this is a polymorphic association. Polymorphic associations were discussed in detail earlier in this guide. -h6. :readonly +h6. +:readonly+ If you set the +:readonly+ option to +true+, then the associated object will be read-only when retrieved via the association. -h6. :select +h6. +:select+ The +:select+ option lets you override the SQL +SELECT+ clause that is used to retrieve data about the associated object. By default, Rails retrieves all columns. TIP: If you set the +:select+ option on a +belongs_to+ association, you should also set the +foreign_key+ option to guarantee the correct results. -h6. :validate +h6. +:validate+ If you set the +:validate+ option to +true+, then associated objects will be validated whenever you save this object. By default, this is +false+: associated objects will not be validated when this object is saved. -h5. When are Objects Saved? +h5. How to know whether there's an associated object? + +To know whether there's and associated object just check association.nil?: + + +if @order.customer.nil? + @msg = "No customer found for this order" +end + + +h5. When are objects saved? Assigning an object to a +belongs_to+ association does _not_ automatically save the object. It does not save the associated object either. -h4. has_one Association Reference +h4. +has_one+ association reference The +has_one+ association creates a one-to-one match with another model. In database terms, this association says that the other class contains the foreign key. If this class contains the foreign key, then you should use +belongs_to+ instead. -h5. Methods Added by has_one +h5. Methods added by +has_one+ -When you declare a +has_one+ association, the declaring class automatically gains five methods related to the association: +When you declare a +has_one+ association, the declaring class automatically gains four methods related to the association: * association(force_reload = false) * association=(associate) -* association.nil? * build_association(attributes = {}) * create_association(attributes = {}) @@ -780,12 +780,11 @@ Each instance of the +Supplier+ model will have these methods: account account= -account.nil? build_account create_account -h6. association(force_reload = false) +h6. association(force_reload = false) The association method returns the associated object, if any. If no associated object is found, it returns +nil+. @@ -795,7 +794,7 @@ The association method returns the associated object, if any. If the associated object has already been retrieved from the database for this object, the cached version will be returned. To override this behavior (and force a database read), pass +true+ as the +force_reload+ argument. -h6. association=(associate) +h6. association=(associate) The association= method assigns an associated object to this object. Behind the scenes, this means extracting the primary key from this object and setting the associate object's foreign key to the same value. @@ -803,33 +802,23 @@ The association= method assigns an associated object to this o @supplier.account = @account -h6. association.nil? - -The association.nil? method returns +true+ if there is no associated object. - - -if @supplier.account.nil? - @msg = "No account found for this supplier" -end - - -h6. build_association(attributes = {}) +h6. build_association(attributes = {}) The build_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through its foreign key will be set, but the associated object will _not_ yet be saved. -@account = @supplier.build_account({:terms => "Net 30"}) +@account = @supplier.build_account(:terms => "Net 30") -h6. create_association(attributes = {}) +h6. create_association(attributes = {}) The create_association method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through its foreign key will be set. In addition, the associated object _will_ be saved (assuming that it passes any validations). -@account = @supplier.create_account({:terms => "Net 30"}) +@account = @supplier.create_account(:terms => "Net 30") -h5. Options for has_one +h5. Options for +has_one+ In many situations, you can use the default behavior of +has_one+ without any customization. But despite Rails' emphasis of convention over customization, you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a +has_one+ association. For example, an association with several options might look like this: @@ -857,17 +846,17 @@ The +has_one+ association supports these options: * +:through+ * +:validate+ -h6. :as +h6. +:as+ -Setting the +:as+ option indicates that this is a polymorphic association. Polymorphic associations were discussed in detail earlier in this guide. +Setting the +:as+ option indicates that this is a polymorphic association. Polymorphic associations were discussed in detail earlier in this guide. -h6. :autosave +h6. +:autosave+ If you set the +:autosave+ option to +true+, Rails will save any loaded members and destroy members that are marked for destruction whenever you save the parent object. -h6. :class_name +h6. +:class_name+ -If the name of the other model cannot be derived from the association name, you can use the +:class_name+ option to supply the model name. For example, if a supplier has an account, but the actual name of the model containing accounts is Billing, you'd set things up this way: +If the name of the other model cannot be derived from the association name, you can use the +:class_name+ option to supply the model name. For example, if a supplier has an account, but the actual name of the model containing accounts is +Billing+, you'd set things up this way: class Supplier < ActiveRecord::Base @@ -875,7 +864,7 @@ class Supplier < ActiveRecord::Base end -h6. :conditions +h6. +:conditions+ The +:conditions+ option lets you specify the conditions that the associated object must meet (in the syntax used by a SQL +WHERE+ clause). @@ -885,11 +874,11 @@ class Supplier < ActiveRecord::Base end -h6. :dependent +h6. +:dependent+ -If you set the +:dependent+ option to +:destroy+, then deleting this object will call the destroy method on the associated object to delete that object. If you set the +:dependent+ option to +:delete+, then deleting this object will delete the associated object _without_ calling its +destroy+ method. If you set the +:dependent+ option to +:nullify+, then deleting this object will set the foreign key in the association object to +NULL+. +If you set the +:dependent+ option to +:destroy+, then deleting this object will call the +destroy+ method on the associated object to delete that object. If you set the +:dependent+ option to +:delete+, then deleting this object will delete the associated object _without_ calling its +destroy+ method. If you set the +:dependent+ option to +:nullify+, then deleting this object will set the foreign key in the association object to +NULL+. -h6. :foreign_key +h6. +:foreign_key+ By convention, Rails guesses that the column used to hold the foreign key on the other model is the name of this model with the suffix +_id+ added. The +:foreign_key+ option lets you set the name of the foreign key directly: @@ -901,7 +890,7 @@ end TIP: In any case, Rails will not create foreign key columns for you. You need to explicitly define them as part of your migrations. -h6. :include +h6. +:include+ You can use the +:include+ option to specify second-order associations that should be eager-loaded when this association is used. For example, consider these models: @@ -937,53 +926,63 @@ class Representative < ActiveRecord::Base end -h6. :order +h6. +:order+ The +:order+ option dictates the order in which associated objects will be received (in the syntax used by a SQL +ORDER BY+ clause). Because a +has_one+ association will only retrieve a single associated object, this option should not be needed. -h6. :primary_key +h6. +:primary_key+ By convention, Rails guesses that the column used to hold the primary key of this model is +id+. You can override this and explicitly specify the primary key with the +:primary_key+ option. -h6. :readonly +h6. +:readonly+ If you set the +:readonly+ option to +true+, then the associated object will be read-only when retrieved via the association. -h6. :select +h6. +:select+ The +:select+ option lets you override the SQL +SELECT+ clause that is used to retrieve data about the associated object. By default, Rails retrieves all columns. -h6. :source +h6. +:source+ The +:source+ option specifies the source association name for a +has_one :through+ association. -h6. :source_type +h6. +:source_type+ The +:source_type+ option specifies the source association type for a +has_one :through+ association that proceeds through a polymorphic association. h6. :through -The +:through+ option specifies a join model through which to perform the query. +has_one :through+ associations were discussed in detail earlier in this guide. +The +:through+ option specifies a join model through which to perform the query. +has_one :through+ associations were discussed in detail earlier in this guide. -h6. :validate +h6. +:validate+ If you set the +:validate+ option to +true+, then associated objects will be validated whenever you save this object. By default, this is +false+: associated objects will not be validated when this object is saved. -h5. When are Objects Saved? +h5. How to know whether there's an associated object? + +To know whether there's and associated object just check association.nil?: + + +if @supplier.account.nil? + @msg = "No account found for this supplier" +end + + +h5. When are objects saved? When you assign an object to a +has_one+ association, that object is automatically saved (in order to update its foreign key). In addition, any object being replaced is also automatically saved, because its foreign key will change too. If either of these saves fails due to validation errors, then the assignment statement returns +false+ and the assignment itself is cancelled. -If the parent object (the one declaring the +has_one+ association) is unsaved (that is, +new_record?+ returns +true+) then the child objects are not saved. +If the parent object (the one declaring the +has_one+ association) is unsaved (that is, +new_record?+ returns +true+) then the child objects are not saved. They will automatically when the parent object is saved. If you want to assign an object to a +has_one+ association without saving the object, use the association.build method. -h4. has_many Association Reference +h4. +has_many+ association reference The +has_many+ association creates a one-to-many relationship with another model. In database terms, this association says that the other class will have a foreign key that refers to instances of this class. -h5. Methods Added +h5. Methods added When you declare a +has_many+ association, the declaring class automatically gains 13 methods related to the association: @@ -1027,7 +1026,7 @@ orders.build(attributes = {}, ...) orders.create(attributes = {}) -h6. collection(force_reload = false) +h6. collection(force_reload = false) The collection method returns an array of all of the associated objects. If there are no associated objects, it returns an empty array. @@ -1035,7 +1034,7 @@ The collection method returns an array of all of the associate @orders = @customer.orders -h6. collection<<(object, ...) +h6. collection<<(object, ...) The collection<< method adds one or more objects to the collection by setting their foreign keys to the primary key of the calling model. @@ -1043,7 +1042,7 @@ The collection<< method adds one or more objects to the collec @customer.orders << @order1 -h6. collection.delete(object, ...) +h6. collection.delete(object, ...) The collection.delete method removes one or more objects from the collection by setting their foreign keys to +NULL+. @@ -1054,11 +1053,11 @@ The collection.delete method removes one or more objects from WARNING: Objects will be in addition destroyed if they're associated with +:dependent => :destroy+, and deleted if they're associated with +:dependent => :delete_all+. -h6. collection=objects +h6. collection=objects The collection= method makes the collection contain only the supplied objects, by adding and deleting as appropriate. -h6. collection_singular_ids +h6. collection_singular_ids The collection_singular_ids method returns an array of the ids of the objects in the collection. @@ -1066,15 +1065,15 @@ The collection_singular_ids method returns an array of the ids @order_ids = @customer.order_ids -h6. collection_singular_ids=ids +h6. collection_singular_ids=ids The collection_singular_ids= method makes the collection contain only the objects identified by the supplied primary key values, by adding and deleting as appropriate. -h6. collection.clear +h6. collection.clear The collection.clear method removes every object from the collection. This destroys the associated objects if they are associated with +:dependent => :destroy+, deletes them directly from the database if +:dependent => :delete_all+, and otherwise sets their foreign keys to +NULL+. -h6. collection.empty? +h6. collection.empty? The collection.empty? method returns +true+ if the collection does not contain any associated objects. @@ -1084,7 +1083,7 @@ The collection.empty? method returns +true+ if the collection <% end %> -h6. collection.size +h6. collection.size The collection.size method returns the number of objects in the collection. @@ -1092,7 +1091,7 @@ The collection.size method returns the number of objects in th @order_count = @customer.orders.size -h6. collection.find(...) +h6. collection.find(...) The collection.find method finds objects within the collection. It uses the same syntax and options as +ActiveRecord::Base.find+. @@ -1100,29 +1099,29 @@ The collection.find method finds objects within the collection @open_orders = @customer.orders.find(:all, :conditions => "open = 1") -h6. collection.exist?(...) +h6. collection.exist?(...) The collection.exist? method checks whether an object meeting the supplied conditions exists in the collection. It uses the same syntax and options as +ActiveRecord::Base.exists?+. -h6. collection.build(attributes = {}, ...) +h6. collection.build(attributes = {}, ...) The collection.build method returns one or more new objects of the associated type. These objects will be instantiated from the passed attributes, and the link through their foreign key will be created, but the associated objects will _not_ yet be saved. -@order = @customer.orders.build({:order_date => Time.now, - :order_number => "A12345"}) +@order = @customer.orders.build(:order_date => Time.now, + :order_number => "A12345") -h6. collection.create(attributes = {}) +h6. collection.create(attributes = {}) The collection.create method returns a new object of the associated type. This object will be instantiated from the passed attributes, the link through its foreign key will be created, and the associated object _will_ be saved (assuming that it passes any validations). -@order = @customer.orders.create({:order_date => Time.now, - :order_number => "A12345"}) +@order = @customer.orders.create(:order_date => Time.now, + :order_number => "A12345") -h5. Options for has_many +h5. Options for +has_many+ In many situations, you can use the default behavior for +has_many+ without any customization. But you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a +has_many+ association. For example, an association with several options might look like this: @@ -1157,15 +1156,15 @@ The +has_many+ association supports these options: * +:uniq+ * +:validate+ -h6. :as +h6. +:as+ -Setting the +:as+ option indicates that this is a polymorphic association, as discussed earlier in this guide. +Setting the +:as+ option indicates that this is a polymorphic association, as discussed earlier in this guide. -h6. :autosave +h6. +:autosave+ If you set the +:autosave+ option to +true+, Rails will save any loaded members and destroy members that are marked for destruction whenever you save the parent object. -h6. :class_name +h6. +:class_name+ If the name of the other model cannot be derived from the association name, you can use the +:class_name+ option to supply the model name. For example, if a customer has many orders, but the actual name of the model containing orders is +Transaction+, you'd set things up this way: @@ -1175,7 +1174,7 @@ class Customer < ActiveRecord::Base end -h6. :conditions +h6. +:conditions+ The +:conditions+ option lets you specify the conditions that the associated object must meet (in the syntax used by a SQL +WHERE+ clause). @@ -1197,27 +1196,27 @@ end If you use a hash-style +:conditions+ option, then record creation via this association will be automatically scoped using the hash. In this case, using +@customer.confirmed_orders.create+ or +@customer.confirmed_orders.build+ will create orders where the confirmed column has the value +true+. -h6. :counter_sql +h6. +:counter_sql+ Normally Rails automatically generates the proper SQL to count the association members. With the +:counter_sql+ option, you can specify a complete SQL statement to count them yourself. NOTE: If you specify +:finder_sql+ but not +:counter_sql+, then the counter SQL will be generated by substituting +SELECT COUNT(*) FROM+ for the +SELECT ... FROM+ clause of your +:finder_sql+ statement. -h6. :dependent +h6. +:dependent+ -If you set the +:dependent+ option to +:destroy+, then deleting this object will call the destroy method on the associated objects to delete those objects. If you set the +:dependent+ option to +:delete_all+, then deleting this object will delete the associated objects _without_ calling their +destroy+ method. If you set the +:dependent+ option to +:nullify+, then deleting this object will set the foreign key in the associated objects to +NULL+. +If you set the +:dependent+ option to +:destroy+, then deleting this object will call the +destroy+ method on the associated objects to delete those objects. If you set the +:dependent+ option to +:delete_all+, then deleting this object will delete the associated objects _without_ calling their +destroy+ method. If you set the +:dependent+ option to +:nullify+, then deleting this object will set the foreign key in the associated objects to +NULL+. NOTE: This option is ignored when you use the +:through+ option on the association. -h6. :extend +h6. +:extend+ -The +:extend+ option specifies a named module to extend the association proxy. Association extensions are discussed in detail later in this guide. +The +:extend+ option specifies a named module to extend the association proxy. Association extensions are discussed in detail later in this guide. -h6. :finder_sql +h6. +:finder_sql+ Normally Rails automatically generates the proper SQL to fetch the association members. With the +:finder_sql+ option, you can specify a complete SQL statement to fetch them yourself. If fetching objects requires complex multi-table SQL, this may be necessary. -h6. :foreign_key +h6. +:foreign_key+ By convention, Rails guesses that the column used to hold the foreign key on the other model is the name of this model with the suffix +_id+ added. The +:foreign_key+ option lets you set the name of the foreign key directly: @@ -1229,7 +1228,7 @@ end TIP: In any case, Rails will not create foreign key columns for you. You need to explicitly define them as part of your migrations. -h6. :group +h6. +:group+ The +:group+ option supplies an attribute name to group the result set by, using a +GROUP BY+ clause in the finder SQL. @@ -1239,7 +1238,7 @@ class Customer < ActiveRecord::Base end -h6. :include +h6. +:include+ You can use the +:include+ option to specify second-order associations that should be eager-loaded when this association is used. For example, consider these models: @@ -1275,7 +1274,7 @@ class LineItem < ActiveRecord::Base end -h6. :limit +h6. +:limit+ The +:limit+ option lets you restrict the total number of objects that will be fetched through an association. @@ -1286,11 +1285,11 @@ class Customer < ActiveRecord::Base end -h6. :offset +h6. +:offset+ The +:offset+ option lets you specify the starting offset for fetching objects via an association. For example, if you set +:offset => 11+, it will skip the first 11 records. -h6. :order +h6. +:order+ The +:order+ option dictates the order in which associated objects will be received (in the syntax used by a SQL +ORDER BY+ clause). @@ -1300,41 +1299,41 @@ class Customer < ActiveRecord::Base end -h6. :primary_key +h6. +:primary_key+ -By convention, Rails guesses that the column used to hold the primary key of this model is +id+. You can override this and explicitly specify the primary key with the +:primary_key+ option. +By convention, Rails guesses that the column used to hold the primary key of the association is +id+. You can override this and explicitly specify the primary key with the +:primary_key+ option. -h6. :readonly +h6. +:readonly+ If you set the +:readonly+ option to +true+, then the associated objects will be read-only when retrieved via the association. -h6. :select +h6. +:select+ The +:select+ option lets you override the SQL +SELECT+ clause that is used to retrieve data about the associated objects. By default, Rails retrieves all columns. WARNING: If you specify your own +:select+, be sure to include the primary key and foreign key columns of the associated model. If you do not, Rails will throw an error. -h6. :source +h6. +:source+ The +:source+ option specifies the source association name for a +has_many :through+ association. You only need to use this option if the name of the source association cannot be automatically inferred from the association name. -h6. :source_type +h6. +:source_type+ The +:source_type+ option specifies the source association type for a +has_many :through+ association that proceeds through a polymorphic association. -h6. :through +h6. +:through+ -The +:through+ option specifies a join model through which to perform the query. +has_many :through+ associations provide a way to implement many-to-many relationships, as discussed earlier in this guide. +The +:through+ option specifies a join model through which to perform the query. +has_many :through+ associations provide a way to implement many-to-many relationships, as discussed earlier in this guide. -h6. :uniq +h6. +:uniq+ Specify the +:uniq => true+ option to remove duplicates from the collection. This is most useful in conjunction with the +:through+ option. -h6. :validate +h6. +:validate+ If you set the +:validate+ option to +false+, then associated objects will not be validated whenever you save this object. By default, this is +true+: associated objects will be validated when this object is saved. -h5. When are Objects Saved? +h5. When are objects saved? When you assign an object to a +has_many+ association, that object is automatically saved (in order to update its foreign key). If you assign multiple objects in one statement, then they are all saved. @@ -1344,11 +1343,11 @@ If the parent object (the one declaring the +has_many+ association) is unsaved ( If you want to assign an object to a +has_many+ association without saving the object, use the collection.build method. -h4. has_and_belongs_to_many Association Reference +h4. +has_and_belongs_to_many+ association reference The +has_and_belongs_to_many+ association creates a many-to-many relationship with another model. In database terms, this associates two classes via an intermediate join table that includes foreign keys referring to each of the classes. -h5. Methods Added +h5. Methods added When you declare a +has_and_belongs_to_many+ association, the declaring class automatically gains 13 methods related to the association: @@ -1392,14 +1391,14 @@ assemblies.build(attributes = {}, ...) assemblies.create(attributes = {}) -h6. Additional Column Methods +h6. Additional column methods If the join table for a +has_and_belongs_to_many+ association has additional columns beyond the two foreign keys, these columns will be added as attributes to records retrieved via that association. Records returned with additional attributes will always be read-only, because Rails cannot save changes to those attributes. WARNING: The use of extra attributes on the join table in a +has_and_belongs_to_many+ association is deprecated. If you require this sort of complex behavior on the table that joins two models in a many-to-many relationship, you should use a +has_many :through+ association instead of +has_and_belongs_to_many+. -h6. collection(force_reload = false) +h6. collection(force_reload = false) The collection method returns an array of all of the associated objects. If there are no associated objects, it returns an empty array. @@ -1407,7 +1406,7 @@ The collection method returns an array of all of the associate @assemblies = @part.assemblies -h6. collection<<(object, ...) +h6. collection<<(object, ...) The collection<< method adds one or more objects to the collection by creating records in the join table. @@ -1417,7 +1416,7 @@ The collection<< method adds one or more objects to the collec NOTE: This method is aliased as collection.concat and collection.push. -h6. collection.delete(object, ...) +h6. collection.delete(object, ...) The collection.delete method removes one or more objects from the collection by deleting records in the join table. This does not destroy the objects. @@ -1425,11 +1424,11 @@ The collection.delete method removes one or more objects from @part.assemblies.delete(@assembly1) -h6. collection=objects +h6. collection=objects The collection= method makes the collection contain only the supplied objects, by adding and deleting as appropriate. -h6. collection_singular_ids +h6. collection_singular_ids The collection_singular_ids method returns an array of the ids of the objects in the collection. @@ -1437,15 +1436,15 @@ The collection_singular_ids method returns an array of the ids @assembly_ids = @part.assembly_ids -h6. collection_singular_ids=ids +h6. collection_singular_ids=ids The collection_singular_ids= method makes the collection contain only the objects identified by the supplied primary key values, by adding and deleting as appropriate. -h6. collection.clear +h6. collection.clear The collection.clear method removes every object from the collection by deleting the rows from the joining table. This does not destroy the associated objects. -h6. collection.empty? +h6. collection.empty? The collection.empty? method returns +true+ if the collection does not contain any associated objects. @@ -1455,7 +1454,7 @@ The collection.empty? method returns +true+ if the collection <% end %> -h6. collection.size +h6. collection.size The collection.size method returns the number of objects in the collection. @@ -1463,7 +1462,7 @@ The collection.size method returns the number of objects in th @assembly_count = @part.assemblies.size -h6. collection.find(...) +h6. collection.find(...) The collection.find method finds objects within the collection. It uses the same syntax and options as +ActiveRecord::Base.find+. It also adds the additional condition that the object must be in the collection. @@ -1472,11 +1471,11 @@ The collection.find method finds objects within the collection :conditions => ["created_at > ?", 2.days.ago]) -h6. collection.exist?(...) +h6. collection.exist?(...) The collection.exist? method checks whether an object meeting the supplied conditions exists in the collection. It uses the same syntax and options as +ActiveRecord::Base.exists?+. -h6. collection.build(attributes = {}) +h6. collection.build(attributes = {}) The collection.build method returns a new object of the associated type. This object will be instantiated from the passed attributes, and the link through the join table will be created, but the associated object will _not_ yet be saved. @@ -1485,7 +1484,7 @@ The collection.build method returns a new object of the associ {:assembly_name => "Transmission housing"}) -h6. collection.create(attributes = {}) +h6. collection.create(attributes = {}) The collection.create method returns a new object of the associated type. This object will be instantiated from the passed attributes, the link through the join table will be created, and the associated object _will_ be saved (assuming that it passes any validations). @@ -1494,7 +1493,7 @@ The collection.create method returns a new object of the assoc {:assembly_name => "Transmission housing"}) -h5. Options for has_and_belongs_to_many +h5. Options for +has_and_belongs_to_many+ In many situations, you can use the default behavior for +has_and_belongs_to_many+ without any customization. But you can alter that behavior in a number of ways. This section covers the options that you can pass when you create a +has_and_belongs_to_many+ association. For example, an association with several options might look like this: @@ -1528,7 +1527,7 @@ The +has_and_belongs_to_many+ association supports these options: * +:uniq+ * +:validate+ -h6. :association_foreign_key +h6. +:association_foreign_key+ By convention, Rails guesses that the column in the join table used to hold the foreign key pointing to the other model is the name of that model with the suffix +_id+ added. The +:association_foreign_key+ option lets you set the name of the foreign key directly: @@ -1542,11 +1541,11 @@ class User < ActiveRecord::Base end -h6. :autosave +h6. +:autosave+ If you set the +:autosave+ option to +true+, Rails will save any loaded members and destroy members that are marked for destruction whenever you save the parent object. -h6. :class_name +h6. +:class_name+ If the name of the other model cannot be derived from the association name, you can use the +:class_name+ option to supply the model name. For example, if a part has many assemblies, but the actual name of the model containing assemblies is +Gadget+, you'd set things up this way: @@ -1556,7 +1555,7 @@ class Parts < ActiveRecord::Base end -h6. :conditions +h6. +:conditions+ The +:conditions+ option lets you specify the conditions that the associated object must meet (in the syntax used by a SQL +WHERE+ clause). @@ -1576,27 +1575,27 @@ class Parts < ActiveRecord::Base end -If you use a hash-style +:conditions+ option, then record creation via this association will be automatically scoped using the hash. In this case, using +@parts.assemblies.create+ or +@parts.assemblies.build+ will create orders where the factory column has the value "Seattle". +If you use a hash-style +:conditions+ option, then record creation via this association will be automatically scoped using the hash. In this case, using +@parts.assemblies.create+ or +@parts.assemblies.build+ will create orders where the +factory+ column has the value "Seattle". -h6. :counter_sql +h6. +:counter_sql+ Normally Rails automatically generates the proper SQL to count the association members. With the +:counter_sql+ option, you can specify a complete SQL statement to count them yourself. NOTE: If you specify +:finder_sql+ but not +:counter_sql+, then the counter SQL will be generated by substituting +SELECT COUNT(*) FROM+ for the +SELECT ... FROM+ clause of your +:finder_sql+ statement. -h6. :delete_sql +h6. +:delete_sql+ Normally Rails automatically generates the proper SQL to remove links between the associated classes. With the +:delete_sql+ option, you can specify a complete SQL statement to delete them yourself. -h6. :extend +h6. +:extend+ -The +:extend+ option specifies a named module to extend the association proxy. Association extensions are discussed in detail later in this guide. +The +:extend+ option specifies a named module to extend the association proxy. Association extensions are discussed in detail later in this guide. -h6. :finder_sql +h6. +:finder_sql+ Normally Rails automatically generates the proper SQL to fetch the association members. With the +:finder_sql+ option, you can specify a complete SQL statement to fetch them yourself. If fetching objects requires complex multi-table SQL, this may be necessary. -h6. :foreign_key +h6. +:foreign_key+ By convention, Rails guesses that the column in the join table used to hold the foreign key pointing to this model is the name of this model with the suffix +_id+ added. The +:foreign_key+ option lets you set the name of the foreign key directly: @@ -1608,7 +1607,7 @@ class User < ActiveRecord::Base end -h6. :group +h6. +:group+ The +:group+ option supplies an attribute name to group the result set by, using a +GROUP BY+ clause in the finder SQL. @@ -1618,19 +1617,19 @@ class Parts < ActiveRecord::Base end -h6. :include +h6. +:include+ You can use the +:include+ option to specify second-order associations that should be eager-loaded when this association is used. -h6. :insert_sql +h6. +:insert_sql+ Normally Rails automatically generates the proper SQL to create links between the associated classes. With the +:insert_sql+ option, you can specify a complete SQL statement to insert them yourself. -h6. :join_table +h6. +:join_table+ If the default name of the join table, based on lexical ordering, is not what you want, you can use the +:join_table+ option to override the default. -h6. :limit +h6. +:limit+ The +:limit+ option lets you restrict the total number of objects that will be fetched through an association. @@ -1641,11 +1640,11 @@ class Parts < ActiveRecord::Base end -h6. :offset +h6. +:offset+ The +:offset+ option lets you specify the starting offset for fetching objects via an association. For example, if you set +:offset => 11+, it will skip the first 11 records. -h6. :order +h6. +:order+ The +:order+ option dictates the order in which associated objects will be received (in the syntax used by a SQL +ORDER BY+ clause). @@ -1655,23 +1654,23 @@ class Parts < ActiveRecord::Base end -h6. :readonly +h6. +:readonly+ If you set the +:readonly+ option to +true+, then the associated objects will be read-only when retrieved via the association. -h6. :select +h6. +:select+ The +:select+ option lets you override the SQL +SELECT+ clause that is used to retrieve data about the associated objects. By default, Rails retrieves all columns. -h6. :uniq +h6. +:uniq+ Specify the +:uniq => true+ option to remove duplicates from the collection. -h6. :validate +h6. +:validate+ If you set the +:validate+ option to +false+, then associated objects will not be validated whenever you save this object. By default, this is +true+: associated objects will be validated when this object is saved. -h5. When are Objects Saved? +h5. When are objects saved? When you assign an object to a +has_and_belongs_to_many+ association, that object is automatically saved (in order to update the join table). If you assign multiple objects in one statement, then they are all saved. @@ -1681,7 +1680,7 @@ If the parent object (the one declaring the +has_and_belongs_to_many+ associatio If you want to assign an object to a +has_and_belongs_to_many+ association without saving the object, use the collection.build method. -h4. Association Callbacks +h4. Association callbacks Normal callbacks hook into the lifecycle of Active Record objects, allowing you to work with those objects at various points. For example, you can use a +:before_save+ callback to cause something to happen just before an object is saved. @@ -1725,7 +1724,7 @@ end If a +before_add+ callback throws an exception, the object does not get added to the collection. Similarly, if a +before_remove+ callback throws an exception, the object does not get removed from the collection. -h4. Association Extensions +h4. Association extensions You're not limited to the functionality that Rails automatically builds into association proxy objects. You can also extend these objects through anonymous modules, adding new finders, creators, or other methods. For example: @@ -1757,7 +1756,7 @@ class Supplier < ActiveRecord::Base end -To include more than one extension module in a single association, specify an array of names: +To include more than one extension module in a single association, specify an array of modules: class Customer < ActiveRecord::Base diff --git a/vendor/rails/railties/guides/source/caching_with_rails.textile b/vendor/rails/railties/guides/source/caching_with_rails.textile index 9736be84..b1c1af8b 100644 --- a/vendor/rails/railties/guides/source/caching_with_rails.textile +++ b/vendor/rails/railties/guides/source/caching_with_rails.textile @@ -500,16 +500,17 @@ seriously considering optimizing their caching needs. Also the new "Cache money":http://github.com/nkallen/cache-money/tree/master plugin is supposed to be mad cool. h3. References - * "RailsEnvy, Rails Caching Tutorial, Part 1":http://www.railsenvy.com/2007/2/28/rails-caching-tutorial - * "RailsEnvy, Rails Caching Tutorial, Part 1":http://www.railsenvy.com/2007/3/20/ruby-on-rails-caching-tutorial-part-2 - * "ActiveSupport::Cache documentation":http://api.rubyonrails.org/classes/ActiveSupport/Cache.html - * "Rails 2.1 integrated caching tutorial":http://thewebfellas.com/blog/2008/6/9/rails-2-1-now-with-better-integrated-caching +* "RailsEnvy, Rails Caching Tutorial, Part 1":http://www.railsenvy.com/2007/2/28/rails-caching-tutorial +* "RailsEnvy, Rails Caching Tutorial, Part 1":http://www.railsenvy.com/2007/3/20/ruby-on-rails-caching-tutorial-part-2 +* "ActiveSupport::Cache documentation":http://api.rubyonrails.org/classes/ActiveSupport/Cache.html +* "Rails 2.1 integrated caching tutorial":http://thewebfellas.com/blog/2008/6/9/rails-2-1-now-with-better-integrated-caching h3. Changelog + "Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/10-guide-to-caching -February 22, 2009: Beefed up the section on cache_stores -December 27, 2008: Typo fixes -November 23, 2008: Incremental updates with various suggested changes and formatting cleanup -September 15, 2008: Initial version by Aditya Chadha +* February 22, 2009: Beefed up the section on cache_stores +* December 27, 2008: Typo fixes +* November 23, 2008: Incremental updates with various suggested changes and formatting cleanup +* September 15, 2008: Initial version by Aditya Chadha diff --git a/vendor/rails/railties/guides/source/index.erb.textile b/vendor/rails/railties/guides/source/index.erb.textile index 4751c3a1..49d8cad4 100644 --- a/vendor/rails/railties/guides/source/index.erb.textile +++ b/vendor/rails/railties/guides/source/index.erb.textile @@ -73,6 +73,10 @@ h3. Digging Deeper
+<% guide("Rails on Rack", 'rails_on_rack.html') do %> + This guide covers Rails integration with Rack and interfacing with other Rack components. +<% end %> + <% guide("Rails Internationalization API", 'i18n.html', :ticket => 23) do %> This guide covers how to add internationalization to your applications. Your application will be able to translate content to different languages, change pluralization rules, use correct date formats for each country and so on. <% end %> @@ -109,8 +113,8 @@ h3. Digging Deeper This guide covers the command line tools and rake tasks provided by Rails. <% end %> -<% guide("Rails on Rack", 'rails_on_rack.html', :ticket => 58) do %> - This guide covers Rails integration with Rack and interfacing with other Rack components. +<% guide("Caching with Rails", 'caching_with_rails.html', :ticket => 10) do %> + Various caching techniques provided by Rails. <% end %>
diff --git a/vendor/rails/railties/guides/source/layouts_and_rendering.textile b/vendor/rails/railties/guides/source/layouts_and_rendering.textile index d9bc605b..5e2cedcf 100644 --- a/vendor/rails/railties/guides/source/layouts_and_rendering.textile +++ b/vendor/rails/railties/guides/source/layouts_and_rendering.textile @@ -683,7 +683,7 @@ Within the context of a layout, +yield+ identifies a section where content from <%= yield %> - + @@ -696,7 +696,7 @@ You can also create a layout with multiple yielding regions: <%= yield %> - + @@ -723,7 +723,7 @@ The result of rendering this page into the supplied layout would be this HTML:

Hello, Rails!

- + @@ -822,7 +822,7 @@ Every partial also has a local variable with the same name as the partial (minus <%= render :partial => "customer", :object => @new_customer %> -Within the +customer+ partial, the +@customer+ variable will refer to +@new_customer+ from the parent view. +Within the +customer+ partial, the +customer+ variable will refer to +@new_customer+ from the parent view. WARNING: In previous versions of Rails, the default local variable would look for an instance variable with the same name as the partial in the parent. This behavior is deprecated in Rails 2.2 and will be removed in a future version. diff --git a/vendor/rails/railties/guides/source/security.textile b/vendor/rails/railties/guides/source/security.textile index 6b84ca19..5797eb88 100644 --- a/vendor/rails/railties/guides/source/security.textile +++ b/vendor/rails/railties/guides/source/security.textile @@ -91,12 +91,12 @@ Rails 2 introduced a new default session storage, CookieStore. CookieStore saves That means the security of this storage depends on this secret (and on the digest algorithm, which defaults to SHA512, which has not been compromised, yet). So _(highlight)don't use a trivial secret, i.e. a word from a dictionary, or one which is shorter than 30 characters_. Put the secret in your environment.rb: -
+
 config.action_controller.session = {
   :key    => '_app_session',
   :secret => '0x0dkfj3927dkc7djdh36rkckdfzsg...'
 }
-
+
There are, however, derivatives of CookieStore which encrypt the session hash, so the client cannot see it. @@ -211,9 +211,9 @@ If your web application is RESTful, you might be used to additional HTTP verbs, _(highlight)The verify method in a controller can make sure that specific actions may not be used over GET_. Here is an example to verify the use of the transfer action over POST. If the action comes in using any other verb, it redirects to the list action. -
+
 verify :method => :post, :only => [:transfer], :redirect_to => {:action => :list}
-
+ With this precaution, the attack from above will not work, because the browser sends a GET request for images, which will not be accepted by the web application. @@ -264,9 +264,9 @@ end This will redirect the user to the main action if he tried to access a legacy action. The intention was to preserve the URL parameters to the legacy action and pass them to the main action. However, it can exploited by an attacker if he includes a host key in the URL: -
+
 http://www.example.com/site/legacy?param1=xy¶m2=23&host=www.attacker.com
-
+ If it is at the end of the URL it will hardly be noticed and redirects the user to the attacker.com host. A simple countermeasure would be to _(highlight)include only the expected parameters in a legacy action_ (again a whitelist approach, as opposed to removing unexpected parameters). _(highlight)And if you redirect to an URL, check it with a whitelist or a regular expression_. @@ -424,10 +424,10 @@ There are some authorization and authentication plug-ins for Rails available. A Every new user gets an activation code to activate his account when he gets an e-mail with a link in it. After activating the account, the activation_code columns will be set to NULL in the database. If someone requested an URL like these, he would be logged in as the first activated user found in the database (and chances are that this is the administrator): -
+
 http://localhost:3006/user/activate
 http://localhost:3006/user/activate?id=
-
+ This is possible because on some servers, this way the parameter id, as in params[:id], would be nil. However, here is the finder from the activation action: @@ -437,9 +437,9 @@ User.find_by_activation_code(params[:id]) If the parameter was nil, the resulting SQL query will be -
+
 SELECT * FROM users WHERE (users.activation_code IS NULL) LIMIT 1
-
+ And thus it found the first user in the database, returned it and logged him in. You can find out more about it in "my blog post":http://www.rorsecurity.info/2007/10/28/restful_authentication-login-security/. _(highlight)It is advisable to update your plug-ins from time to time_. Moreover, you can review your application to find more flaws like this. @@ -534,9 +534,9 @@ end This means, upon saving, the model will validate the file name to consist only of alphanumeric characters, dots, + and -. And the programmer added \^ and $ so that file name will contain these characters from the beginning to the end of the string. However, _(highlight)in Ruby ^ and $ matches the *line* beginning and line end_. And thus a file name like this passes the filter without problems: -
+
 file.txt%0A
-
+ Whereas %0A is a line feed in URL encoding, so Rails automatically converts it to "file.txt\n<script>alert('hello')</script>". This file name passes the filter because the regular expression matches – up to the line end, the rest does not matter. The correct expression should read: @@ -599,9 +599,9 @@ Project.find(:all, :conditions => "name = '#{params[:name]}'") This could be in a search action and the user may enter a project's name that he wants to find. If a malicious user enters ' OR 1=1', the resulting SQL query will be: -
+
 SELECT * FROM projects WHERE name = '' OR 1 --'
-
+ The two dashes start a comment ignoring everything after it. So the query returns all records from the projects table including those blind to the user. This is because the condition is true for all records. @@ -615,9 +615,9 @@ User.find(:first, "login = '#{params[:name]}' AND password = '#{params[:password If an attacker enters ' OR '1'='1 as the name, and ' OR '2'>'1 as the password, the resulting SQL query will be: -
+
 SELECT * FROM users WHERE login = '' OR '1'='1' AND password = '' OR '2'>'1' LIMIT 1
-
+ This will simply find the first record in the database, and grants access to this user. @@ -631,16 +631,16 @@ Project.find(:all, :conditions => "name = '#{params[:name]}'") And now let's inject another query using the UNION statement: -
+
 ') UNION SELECT id,login AS name,password AS description,1,1,1 FROM users --
-
+ This will result in the following SQL query: -
+
 SELECT * FROM projects WHERE (name = '') UNION
   SELECT id,login AS name,password AS description,1,1,1 FROM users --')
-
+ The result won't be a list of projects (because there is no project with an empty name), but a list of user names and their password. So hopefully you encrypted the passwords in the database! The only problem for the attacker is, that the number of columns has to be the same in both queries. That's why the second query includes a list of ones (1), which will be always the value 1, in order to match the number of columns in the first query. @@ -686,36 +686,36 @@ The most common XSS language is of course the most popular client-side scripting Here is the most straightforward test to check for XSS: -
+
 
-
+ This JavaScript code will simply display an alert box. The next examples do exactly the same, only in very uncommon places: -
+
 
 
-
+
 
 h6. Cookie theft
 
 These examples don't do any harm so far, so let's see how an attacker can steal the user's cookie (and thus hijack the user's session). In JavaScript you can use the document.cookie property to read and write the document's cookie. JavaScript enforces the same origin policy, that means a script from one domain cannot access cookies of another domain. The document.cookie property holds the cookie of the originating web server. However, you can read and write this property, if you embed the code directly in the HTML document (as it happens with XSS). Inject this anywhere in your web application to see your own cookie on the result page:
 
-
+
 
-
+ For an attacker, of course, this is not useful, as the victim will see his own cookie. The next example will try to load an image from the URL http://www.attacker.com/ plus the cookie. Of course this URL does not exist, so the browser displays nothing. But the attacker can review his web server's access log files to see the victims cookie. -
+
 
-
+ The log files on www.attacker.com will read like this: -
+
 GET http://www.attacker.com/_app_session=836c1c25278e5b321d6bea4f19cb57e2
-
+ You can mitigate these attacks (in the obvious way) by adding the "httpOnly":http://dev.rubyonrails.org/ticket/8895 flag to cookies, so that document.cookie may not be read by JavaScript. Http only cookies can be used from IE v6.SP1, Firefox v2.0.0.5 and Opera 9.5. Safari is still considering, it ignores the option. But other, older browsers (such as WebTV and IE 5.5 on Mac) can actually cause the page to fail to load. Be warned that cookies "will still be visible using Ajax":http://ha.ckers.org/blog/20070719/firefox-implements-httponly-and-is-vulnerable-to-xmlhttprequest/, though. @@ -723,9 +723,9 @@ h6. Defacement With web page defacement an attacker can do a lot of things, for example, present false information or lure the victim on the attackers web site to steal the cookie, login credentials or other sensitive data. The most popular way is to include code from external sources by iframes: -
+
 
-
+ This loads arbitrary HTML and/or JavaScript from an external source and embeds it as part of the site. This iFrame is taken from an "actual attack":http://www.symantec.com/enterprise/security_response/weblog/2007/06/italy_under_attack_mpack_gang.html on legitimate Italian sites using the "Mpack attack framework":http://isc.sans.org/diary.html?storyid=3015. Mpack tries to install malicious software through security holes in the web browser – very successfully, 50% of the attacks succeed. @@ -733,10 +733,10 @@ A more specialized attack could overlap the entire web site or display a login f Reflected injection attacks are those where the payload is not stored to present it to the victim later on, but included in the URL. Especially search forms fail to escape the search string. The following link presented a page which stated that "George Bush appointed a 9 year old boy to be the chairperson...": -
+
 http://www.cbsnews.com/stories/2002/02/15/weather_local/main501644.shtml?zipcode=1-->