From d167cfd62b31333e11fcb9de4ea33dfabde7fa82 Mon Sep 17 00:00:00 2001 From: Jaime Iniesta Date: Thu, 1 Jul 2010 12:10:07 +0200 Subject: Fixes README for generated apps with Rails 3 (rails *new* myapp, and Welcome aboard text) --- railties/README | 4 ++-- railties/lib/rails/generators/rails/app/templates/README | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/README b/railties/README index b8c84dd07d..d8be15e346 100644 --- a/railties/README +++ b/railties/README @@ -29,13 +29,13 @@ link:files/vendor/rails/actionpack/README.html. == Getting Started 1. At the command prompt, create a new Rails application: - rails myapp (where myapp is the application name) + rails new myapp (where myapp is the application name) 2. Change directory to myapp and start the web server: cd myapp; rails server (run with --help for options) 3. Go to http://localhost:3000/ and you'll see: - "Welcome aboard: You're riding the Rails!" + "Welcome aboard: You're riding Ruby on Rails!" 4. Follow the guidelines to start developing your application. You can find the following resources handy: diff --git a/railties/lib/rails/generators/rails/app/templates/README b/railties/lib/rails/generators/rails/app/templates/README index e2764dee03..6966fe987e 100644 --- a/railties/lib/rails/generators/rails/app/templates/README +++ b/railties/lib/rails/generators/rails/app/templates/README @@ -35,7 +35,7 @@ link:files/vendor/rails/actionpack/README.html. cd myapp; rails server (run with --help for options) 3. Go to http://localhost:3000/ and you'll see: - "Welcome aboard: You're riding the Rails!" + "Welcome aboard: You're riding Ruby on Rails!" 4. Follow the guidelines to start developing your application. You can find the following resources handy: -- cgit v1.2.3 From 53b34e84762b7f2d6b641f99dadbb1eab42907ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 1 Jul 2010 17:07:48 +0200 Subject: Avoid calls to Rails::Application since this is not the official API. Your application should *always* reference your application const (as Blog::Application) and Rails.application should be used just internally. --- railties/guides/source/initialization.textile | 72 ++++++++-------------- railties/lib/rails/application.rb | 12 ++-- railties/lib/rails/commands.rb | 10 +-- railties/lib/rails/commands/runner.rb | 2 +- .../rails/generators/rails/app/templates/Rakefile | 2 +- .../config/initializers/secret_token.rb.tt | 2 +- .../config/initializers/session_store.rb.tt | 4 +- railties/lib/rails/info_routes.rb | 2 +- railties/lib/rails/tasks/middleware.rake | 2 +- railties/lib/rails/tasks/routes.rake | 2 +- .../application/initializers/frameworks_test.rb | 2 +- .../test/application/initializers/i18n_test.rb | 2 +- railties/test/application/rake_test.rb | 4 +- railties/test/rails_info_controller_test.rb | 2 +- 14 files changed, 48 insertions(+), 72 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index e458413b35..cedf823bdc 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -11,7 +11,7 @@ This guide first describes the process of +rails server+ then explains the Passe h3. Launch! -As of Rails 3, +script/server+ has become +rails server+. This was done to centralise all rails related commands to one common file. +As of Rails 3, +script/server+ has become +rails server+. This was done to centralize all rails related commands to one common file. The actual +rails+ command is kept in _railties/bin/rails_ and goes like this: @@ -58,11 +58,8 @@ In +script/rails+ we see the following: #!/usr/bin/env ruby # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. - ENV_PATH = File.expand_path('../../config/environment', __FILE__) - BOOT_PATH = File.expand_path('../../config/boot', __FILE__) - APP_PATH = File.expand_path('../../config/application', __FILE__) - - require BOOT_PATH + APP_PATH = File.expand_path('../../config/application', __FILE__) + require File.expand_path('../../config/boot', __FILE__) require 'rails/commands' @@ -79,15 +76,19 @@ h3. _config/boot.rb_ _config/boot.rb_ is the first stop for everything for initializing your application. This boot process does quite a bit of work for you and so this section attempts to go in-depth enough to explain what each of the pieces does. - # Use Bundler (preferred) + require 'rubygems' + + # Set up gems listed in the Gemfile. + gemfile = File.expand_path('../../Gemfile', __FILE__) begin - require File.expand_path('../../.bundle/environment', __FILE__) - rescue LoadError - require 'rubygems' + ENV['BUNDLE_GEMFILE'] = gemfile require 'bundler' Bundler.setup - end - + rescue Bundler::GemNotFound => e + STDERR.puts e.message + STDERR.puts "Try running `bundle install`." + exit! + end if File.exist?(gemfile) h3. Bundled Rails (3.x) @@ -164,33 +165,7 @@ TODO: Prettify when it becomes more stable. I won't go into what each of these gems are, as that is really something that needs covering on a case-by-case basis. We will however just dig a little under the surface of Bundler. -Back in _config/boot.rb_, the first line will try to include _.bundle/environment.rb_, which doesn't exist in a bare-bones Rails application and because this file does not exist Ruby will raise a +LoadError+ which will be rescued and run the following code: - - - require 'rubygems' - require 'bundler' - Bundler.setup - - -+Bundler.setup+ here will load and parse the +Gemfile+ and add the _lib_ directory of the gems mentioned **and** their dependencies (**and** their dependencies' dependencies, and so on) to the +$LOAD_PATH+. - -Now we will go down the alternate timeline where we generate a _.bundle/environment.rb_ file using the +bundle lock+ command. This command also creates a _Gemfile.lock_ file which is actually a YAML file loaded by this method in Bundler before it moves on to check for _Gemfile_: - - - def definition(gemfile = default_gemfile) - configure - root = Pathname.new(gemfile).dirname - lockfile = root.join("Gemfile.lock") - if lockfile.exist? - Definition.from_lock(lockfile) - else - Definition.from_gemfile(gemfile) - end - end - - - -The _.bundle/environment.rb_ file adds the _lib_ directory of all the gems specified in +Gemfile.lock+ to +$LOAD_PATH+. +Back in _config/boot.rb_, we call +Bundler.setup+ which will load and parse the +Gemfile+ and add the _lib_ directory of the gems mentioned **and** their dependencies (**and** their dependencies' dependencies, and so on) to the +$LOAD_PATH+. h3. Requiring Rails @@ -326,6 +301,11 @@ As you can see for the duration of the +eager_autoload+ block the class variable module ActiveSupport extend ActiveSupport::Autoload + autoload :DescendantsTracker + autoload :FileUpdateChecker + autoload :LogSubscriber + autoload :Notifications + # TODO: Narrow this list down eager_autoload do autoload :BacktraceCleaner @@ -348,7 +328,6 @@ As you can see for the duration of the +eager_autoload+ block the class variable autoload :OptionMerger autoload :OrderedHash autoload :OrderedOptions - autoload :Notifications autoload :Rescuable autoload :SecureRandom autoload :StringInquirer @@ -589,19 +568,20 @@ This file (_railties/lib/rails.rb_) requires the very, very basics that Rails ne require 'action_dispatch/railtie' -+require 'pathname'+ requires the Pathname class which is used for returning a Pathname object for +Rails.root+ so that instead of doing: ++require 'pathname'+ requires the Pathname class which is used for returning a Pathname object for +Rails.root+. Although is coming to use this path name to generate paths as below: - File.join(Rails.root, "app/controllers") + Rails.root.join("app/controllers") -You may do: +Pathname can also be converted to string, so the following syntax is preferred: - Rails.root.join("app/controllers") + "#{Rails.root}/app/controllers" -Although this is not new to Rails 3 (it was available in 2.3.5), it is something worthwhile pointing out. + +This works because Ruby automatically handles file path conversions. Although this is not new to Rails 3 (it was available in 2.3.5), it is something worthwhile pointing out. Inside this file there are other helpful helper methods defined, such as +Rails.root+, +Rails.env+, +Rails.logger+ and +Rails.application+. @@ -1833,7 +1813,7 @@ We do not already have a +Rails.application+, so instead this resorts to calling end -This +called_from+ setting looks a little overwhelming to begin with, but the short end of it is that it returns the route to your application's config directory, something like: _/home/you/yourapp/config_. After +called_from+ has been set, +super+ is again called and this means the +Rails::Railtie#inherited+ method (in _railties/lib/rails/railtie.rb_): +This +called_from+ setting looks a little overwhelming to begin with, but the short end of it is that it returns your application's root, something like: _/home/you/yourapp_. After +called_from+ has been set, +super+ is again called and this means the +Rails::Railtie#inherited+ method (in _railties/lib/rails/railtie.rb_): def inherited(base) diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 4a7ed2d028..f61103c764 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -8,14 +8,6 @@ module Rails # In Rails 3.0, a Rails::Application object was introduced which is nothing more than # an Engine but with the responsibility of coordinating the whole boot process. # - # Opposite to Rails::Engine, you can only have one Rails::Application instance - # in your process and both Rails::Application and YourApplication::Application - # points to it. - # - # In other words, Rails::Application is Singleton and whenever you are accessing - # Rails::Application.config or YourApplication::Application.config, you are actually - # accessing YourApplication::Application.instance.config. - # # == Initialization # # Rails::Application is responsible for executing all railties, engines and plugin @@ -57,6 +49,10 @@ module Rails def instance if self == Rails::Application + if Rails.application + ActiveSupport::Deprecation.warn "Calling a method in Rails::Application is deprecated, " << + "please call it directly in your application constant #{Rails.application.class.name}.", caller + end Rails.application else @@instance ||= new diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb index aad1170b56..b9353ba336 100644 --- a/railties/lib/rails/commands.rb +++ b/railties/lib/rails/commands.rb @@ -13,27 +13,27 @@ command = aliases[command] || command case command when 'generate', 'destroy', 'plugin', 'benchmarker', 'profiler' require APP_PATH - Rails::Application.require_environment! + Rails.application.require_environment! require "rails/commands/#{command}" when 'console' require 'rails/commands/console' require APP_PATH - Rails::Application.require_environment! - Rails::Console.start(Rails::Application) + Rails.application.require_environment! + Rails::Console.start(Rails.application) when 'server' require 'rails/commands/server' Rails::Server.new.tap { |server| require APP_PATH - Dir.chdir(Rails::Application.root) + Dir.chdir(Rails.application.root) server.start } when 'dbconsole' require 'rails/commands/dbconsole' require APP_PATH - Rails::DBConsole.start(Rails::Application) + Rails::DBConsole.start(Rails.application) when 'application', 'runner' require "rails/commands/#{command}" diff --git a/railties/lib/rails/commands/runner.rb b/railties/lib/rails/commands/runner.rb index b97ff086b6..c43a233bc3 100644 --- a/railties/lib/rails/commands/runner.rb +++ b/railties/lib/rails/commands/runner.rb @@ -37,7 +37,7 @@ ARGV.delete(code_or_file) ENV["RAILS_ENV"] = options[:environment] require APP_PATH -Rails::Application.require_environment! +Rails.application.require_environment! begin if code_or_file.nil? diff --git a/railties/lib/rails/generators/rails/app/templates/Rakefile b/railties/lib/rails/generators/rails/app/templates/Rakefile index 13f1f9fa41..d83cafc3be 100644 --- a/railties/lib/rails/generators/rails/app/templates/Rakefile +++ b/railties/lib/rails/generators/rails/app/templates/Rakefile @@ -4,4 +4,4 @@ require File.expand_path('../config/application', __FILE__) require 'rake' -Rails::Application.load_tasks +<%= app_const %>.load_tasks diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/secret_token.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/secret_token.rb.tt index 22aa576f5d..a3143f1346 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/secret_token.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/secret_token.rb.tt @@ -4,4 +4,4 @@ # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. -Rails.application.config.secret_token = '<%= app_secret %>' +<%= app_const %>.config.secret_token = '<%= app_secret %>' diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt index a869a21e2c..0aed79bb70 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt @@ -1,8 +1,8 @@ # Be sure to restart your server when you modify this file. -Rails.application.config.session_store :cookie_store, :key => '_<%= app_name %>_session' +<%= app_const %>.config.session_store :cookie_store, :key => '_<%= app_name %>_session' # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information # (create the session table with "rake db:sessions:create") -# Rails.application.config.session_store :active_record_store +# <%= app_const %>.config.session_store :active_record_store diff --git a/railties/lib/rails/info_routes.rb b/railties/lib/rails/info_routes.rb index bd58034d8f..b5c4e4c1e0 100644 --- a/railties/lib/rails/info_routes.rb +++ b/railties/lib/rails/info_routes.rb @@ -1,3 +1,3 @@ -Rails.application.routes.draw do |map| +Rails.application.routes.draw do match '/rails/info/properties' => "rails/info#properties" end diff --git a/railties/lib/rails/tasks/middleware.rake b/railties/lib/rails/tasks/middleware.rake index e670989345..cd35ffb19a 100644 --- a/railties/lib/rails/tasks/middleware.rake +++ b/railties/lib/rails/tasks/middleware.rake @@ -3,5 +3,5 @@ task :middleware => :environment do Rails.configuration.middleware.each do |middleware| puts "use #{middleware.inspect}" end - puts "run #{Rails::Application.instance.class.name}.routes" + puts "run #{Rails.application.class.name}.routes" end diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake index 41619bc1f8..a99232c4be 100644 --- a/railties/lib/rails/tasks/routes.rake +++ b/railties/lib/rails/tasks/routes.rake @@ -1,6 +1,6 @@ desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.' task :routes => :environment do - Rails::Application.reload_routes! + Rails.application.reload_routes! all_routes = ENV['CONTROLLER'] ? Rails.application.routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : Rails.application.routes.routes routes = all_routes.collect do |route| # TODO: The :index method is deprecated in 1.9 in favor of :key diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index 7269a7c5a8..b1deb7a645 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -36,7 +36,7 @@ module ApplicationTests test "allows me to configure default url options for ActionMailer" do app_file "config/environments/development.rb", <<-RUBY - Rails::Application.configure do + AppTemplate::Application.configure do config.action_mailer.default_url_options = { :host => "test.rails" } end RUBY diff --git a/railties/test/application/initializers/i18n_test.rb b/railties/test/application/initializers/i18n_test.rb index a1fcba3310..4baa8a8170 100644 --- a/railties/test/application/initializers/i18n_test.rb +++ b/railties/test/application/initializers/i18n_test.rb @@ -16,7 +16,7 @@ module ApplicationTests end def app - @app ||= Rails::Application + @app ||= Rails.application end def assert_fallbacks(fallbacks) diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 40fb446b16..d6e100ffe3 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -24,11 +24,11 @@ module ApplicationTests app_file "config/environment.rb", <<-RUBY SuperMiddleware = Struct.new(:app) - Rails::Application.configure do + AppTemplate::Application.configure do config.middleware.use SuperMiddleware end - Rails::Application.initialize! + AppTemplate::Application.initialize! RUBY assert_match "SuperMiddleware", Dir.chdir(app_path){ `rake middleware` } diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb index aa76979c27..687c2d1568 100644 --- a/railties/test/rails_info_controller_test.rb +++ b/railties/test/rails_info_controller_test.rb @@ -11,7 +11,7 @@ class InfoControllerTest < ActionController::TestCase tests Rails::InfoController def setup - Rails.application.routes.draw do |map| + Rails.application.routes.draw do match '/rails/info/properties' => "rails/info#properties" end @controller.stubs(:consider_all_requests_local? => false, :local_request? => true) -- cgit v1.2.3 From d7c1057652cfc971bb35ef09b0b1560fcd28ed70 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 1 Jul 2010 02:25:35 -0700 Subject: Bump bundler dependency to 1.0.0.beta.2 or later --- railties/guides/source/initialization.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index cedf823bdc..8498f79f4e 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -141,7 +141,7 @@ Here the only two gems we need are +rails+ and +sqlite3-ruby+, so it seems. This * activesupport-3.0.0.beta4.gem * arel-0.4.0.gem * builder-2.1.2.gem -* bundler-0.9.26.gem +* bundler-1.0.0.beta.2.gem * erubis-2.6.5.gem * i18n-0.4.1.gem * mail-2.2.4.gem -- cgit v1.2.3 From 2ef8a2b403adcee21fe1a5bfadc125b24779cd53 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 1 Jul 2010 16:59:31 -0300 Subject: bump erubis version to 2.6.6 and thor version to 0.13.7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- railties/guides/source/initialization.textile | 4 ++-- railties/railties.gemspec | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 8498f79f4e..9a0e23385d 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -142,7 +142,7 @@ Here the only two gems we need are +rails+ and +sqlite3-ruby+, so it seems. This * arel-0.4.0.gem * builder-2.1.2.gem * bundler-1.0.0.beta.2.gem -* erubis-2.6.5.gem +* erubis-2.6.6.gem * i18n-0.4.1.gem * mail-2.2.4.gem * memcache-client-1.8.3.gem @@ -157,7 +157,7 @@ Here the only two gems we need are +rails+ and +sqlite3-ruby+, so it seems. This * sqlite3-ruby-1.3.0.gem * text-format-1.0.0.gem * text-hyphen-1.0.0.gem -* thor-0.13.6.gem +* thor-0.13.7.gem * treetop-1.4.8.gem * tzinfo-0.3.22.gem diff --git a/railties/railties.gemspec b/railties/railties.gemspec index 99537d6d24..247b926af9 100644 --- a/railties/railties.gemspec +++ b/railties/railties.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |s| s.has_rdoc = false s.add_dependency('rake', '>= 0.8.3') - s.add_dependency('thor', '~> 0.13.6') + s.add_dependency('thor', '~> 0.13.7') s.add_dependency('activesupport', version) s.add_dependency('actionpack', version) end -- cgit v1.2.3 From 0189fb76e3c38ef9a0d292135683b0d135c4a369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 2 Jul 2010 08:13:52 +0200 Subject: reload_routes! was still referencing old Rails::Application. --- railties/lib/rails/application.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index f61103c764..458177b954 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -121,14 +121,13 @@ module Rails end def reload_routes! - routes = Rails::Application.routes - routes.disable_clear_and_finalize = true - - routes.clear! + _routes = self.routes + _routes.disable_clear_and_finalize = true + _routes.clear! routes_reloader.paths.each { |path| load(path) } - ActiveSupport.on_load(:action_controller) { routes.finalize! } + ActiveSupport.on_load(:action_controller) { _routes.finalize! } ensure - routes.disable_clear_and_finalize = false + _routes.disable_clear_and_finalize = false end def initialize! -- cgit v1.2.3 From aeaa4687ea5802089a99e0fd96b10ed5c463cd21 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 2 Jul 2010 11:32:05 -0700 Subject: Fix indent --- railties/test/application/runner_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/test/application/runner_test.rb b/railties/test/application/runner_test.rb index d37b7649e2..07a3d94120 100644 --- a/railties/test/application/runner_test.rb +++ b/railties/test/application/runner_test.rb @@ -19,7 +19,7 @@ module ApplicationTests end def test_should_run_ruby_statement - assert_match "42", Dir.chdir(app_path) { `bundle exec rails runner "puts User.count"` } + assert_match "42", Dir.chdir(app_path) { `bundle exec rails runner "puts User.count"` } end def test_should_run_file -- cgit v1.2.3 From 5360014a5d77e8b6db71530dae49ac651392536d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=A3is=20Ozols?= Date: Sat, 3 Jul 2010 03:16:04 +0300 Subject: Changed passed argument to :validate => false in validation skipping section. --- railties/guides/source/active_record_validations_callbacks.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index cfd4ae55cc..84c33e34f9 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -86,9 +86,9 @@ The following methods skip validations, and will save the object to the database * +update_attribute+ * +update_counters+ -Note that +save+ also has the ability to skip validations if passed +false+ as argument. This technique should be used with caution. +Note that +save+ also has the ability to skip validations if passed +:validate => false+ as argument. This technique should be used with caution. -* +save(false)+ +* +save(:validate => false)+ h4. +valid?+ and +invalid?+ -- cgit v1.2.3 From 52e526a8e3ed3682ae2b774e4a328b9aa8bd6dde Mon Sep 17 00:00:00 2001 From: Andrew White Date: Sat, 3 Jul 2010 09:01:01 +0100 Subject: :singular is no longer a valid option for resources [#5037 state:resolved] --- railties/guides/source/routing.textile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile index 9ff06856c3..3562030aa9 100644 --- a/railties/guides/source/routing.textile +++ b/railties/guides/source/routing.textile @@ -714,14 +714,14 @@ Rails now creates routes to the +CategoriesControlleR+. h4. Overriding the Singular Form -If you want to customize the singular name of the route in the named helpers, you can use the +:singular+ option. +If you want to define the singular form of a resource, you should add additional rules to the +Inflector+. -resources :teeth, :singular => "tooth" +ActiveSupport::Inflector.inflections do |inflect| + inflect.irregular 'tooth', 'teeth' +end -TIP: If you want to define the singular form of a word for your entire application, you should add additional rules to the +Inflector+ instead. - h4(#nested-name-prefix). Using +:name_prefix+ in Nested Resources The +:name_prefix+ option overrides the automatically-generated prefix for the parent resource in nested route helpers. For example, -- cgit v1.2.3 From 547199ee4a279cf885ee6c4e3a605f64f70c9310 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Sat, 3 Jul 2010 09:18:02 +0100 Subject: Updated routing guide to reflect the fact that :name_prefix is now :as --- railties/guides/source/routing.textile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile index 3562030aa9..4e55b07ed7 100644 --- a/railties/guides/source/routing.textile +++ b/railties/guides/source/routing.textile @@ -647,11 +647,11 @@ end h4. Overriding the Named Helper Prefix -You can use the :name_prefix option to add a prefix to the named route helpers that Rails generates for a route. You can use this option to prevent collisions between routes using a path scope. +You can use the :as option to rename the named route helpers that Rails generates for a route. You can use this option to prevent collisions between routes using a path scope. scope "admin" do - resources :photos, :name_prefix => "admin" + resources :photos, :as => "admin_photos" end resources :photos @@ -662,14 +662,14 @@ This will provide route helpers such as +admin_photos_path+, +new_admin_photo_pa You could specify a name prefix to use for a group of routes in the scope: -scope "admin", :name_prefix => "admin" do +scope "admin", :as => "admin" do resources :photos, :accounts end resources :photos, :accounts -NOTE: The +namespace+ scope will automatically add a +:name_prefix+ as well as +:module+ and +:path+ prefixes. +NOTE: The +namespace+ scope will automatically add +:as+ as well as +:module+ and +:path+ prefixes. h4. Restricting the Routes Created @@ -722,13 +722,13 @@ ActiveSupport::Inflector.inflections do |inflect| end -h4(#nested-name-prefix). Using +:name_prefix+ in Nested Resources +h4(#nested-names). Using +:as+ in Nested Resources -The +:name_prefix+ option overrides the automatically-generated prefix for the parent resource in nested route helpers. For example, +The +:as+ option overrides the automatically-generated name for the resource in nested route helpers. For example, resources :magazines do - resources :ads, :name_prefix => 'periodical' + resources :ads, :as => 'periodical_ads' end -- cgit v1.2.3 From a7988fcf4149ab61c83ade5d380ae5d30789efc8 Mon Sep 17 00:00:00 2001 From: Jeff Dean Date: Sun, 4 Jul 2010 00:35:34 -0400 Subject: Added release notes for 3 changes to helpers --- railties/guides/source/3_0_release_notes.textile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/3_0_release_notes.textile b/railties/guides/source/3_0_release_notes.textile index b32ca4fce9..7dcaf508c6 100644 --- a/railties/guides/source/3_0_release_notes.textile +++ b/railties/guides/source/3_0_release_notes.textile @@ -339,7 +339,9 @@ h5. Other Changes * You no longer need to place a minus sign at the end of a ruby interpolation inside an ERb template to remove the trailing carriage return in the HTML output. * Added +grouped_collection_select+ helper to Action View. * +content_for?+ has been added allowing you to check for the existence of content in a view before rendering. - +* passing +:value => nil+ to form helpers will set the field's +value+ attribute to nil as opposed to using the default value +* passing +:id => nil+ to form helpers will cause those fields to be rendered with no +id+ attribute +* passing +:alt => nil+ to +image_tag+ will cause the +img+ tag to render with no +alt+ attribute h3. Active Model -- cgit v1.2.3 From 7d04a4be6b744fd1de9dc906a2faf83fffc9e0cc Mon Sep 17 00:00:00 2001 From: Andrew White Date: Sun, 4 Jul 2010 08:05:11 +0100 Subject: Reword routing guide so that we talk about prefixing as a use of :as rather than as a specific prefixing option (which :name_prefix used to be). --- railties/guides/source/routing.textile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile index 4e55b07ed7..00755071c5 100644 --- a/railties/guides/source/routing.textile +++ b/railties/guides/source/routing.textile @@ -645,9 +645,9 @@ scope :path_names => { :new => "make" } do end -h4. Overriding the Named Helper Prefix +h4. Prefixing the Named Route Helpers -You can use the :as option to rename the named route helpers that Rails generates for a route. You can use this option to prevent collisions between routes using a path scope. +You can use the +:as+ option to prefix the named route helpers that Rails generates for a route. Use this option to prevent name collisions between routes using a path scope. scope "admin" do @@ -659,7 +659,7 @@ resources :photos This will provide route helpers such as +admin_photos_path+, +new_admin_photo_path+ etc. -You could specify a name prefix to use for a group of routes in the scope: +To prefix a group of routes, use +:as+ with +scope+: scope "admin", :as => "admin" do -- cgit v1.2.3 From 3cb53758324214ec8bc65979f47dd43d0e85a248 Mon Sep 17 00:00:00 2001 From: Madjo DIAPENA Date: Sun, 4 Jul 2010 17:41:08 +0200 Subject: ARGV.empty? is useless. If ARGV is empty, ARGV.first != "new" will always be true MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- railties/lib/rails/commands/application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/commands/application.rb b/railties/lib/rails/commands/application.rb index a3a5aed399..47c6752ca3 100644 --- a/railties/lib/rails/commands/application.rb +++ b/railties/lib/rails/commands/application.rb @@ -4,7 +4,7 @@ if %w(--version -v).include? ARGV.first exit(0) end -if ARGV.first != "new" || ARGV.empty? +if ARGV.first != "new" ARGV[0] = "--help" else ARGV.shift -- cgit v1.2.3 From a5dda97602f2188a13cbcab5c7e9a5ba84ba876b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 5 Jul 2010 12:50:08 +0200 Subject: Define a convention for descendants and subclasses. The former should be symmetric with ancestors and include all children. However, it should not include self since ancestors + descendants should not have duplicated. The latter is symmetric to superclass in the sense it only includes direct children. By adopting a convention, we expect to have less conflict with other frameworks, as Datamapper. For this moment, to ensure ActiveModel::Validations can be used with Datamapper, we should always call ActiveSupport::DescendantsTracker.descendants(self) internally instead of self.descendants avoiding conflicts. --- .../source/active_support_core_extensions.textile | 81 ++++++++-------------- 1 file changed, 29 insertions(+), 52 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 844b9428bd..de0c00ac68 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -387,40 +387,6 @@ TIP: Since +with_options+ forwards calls to its receiver they can be nested. Eac NOTE: Defined in +active_support/core_ext/object/with_options.rb+. -h5. +subclasses_of+ - -The method +subclasses_of+ receives an arbitrary number of class objects and returns all their anonymous or reachable descendants as a single array: - - -class C; end -subclasses_of(C) # => [] - -subclasses_of(Integer) # => [Bignum, Fixnum] - -module M - class A; end - class B1 < A; end - class B2 < A; end -end - -module N - class C < M::B1; end -end - -subclasses_of(M::A) # => [N::C, M::B2, M::B1] - - -The order in which these classes are returned is unspecified. The returned collection may have duplicates: - - -subclasses_of(Numeric, Integer) -# => [Bignum, Float, Fixnum, Integer, Date::Infinity, Rational, BigDecimal, Bignum, Fixnum] - - -See also +Class#subclasses+ in "Extensions to +Class+ FIX THIS LINK":FIXME. - -NOTE: Defined in +active_support/core_ext/object/extending.rb+. - h4. Instance Variables Active Support provides several methods to ease access to instance variables. @@ -1141,36 +1107,47 @@ If for whatever reason an application loads the definition of a mailer class and NOTE: Defined in +active_support/core_ext/class/delegating_attributes.rb+. -h4. Descendants +h4. Descendants & Subclasses -h5. +subclasses+ +h5. +descendants+ -The +subclasses+ method returns the names of all the anonymous or reachable descendants of its receiver as an array of strings: +The +descendants+ method returns all classes, including its children, that inherits from self. class C; end -C.subclasses # => [] - -Integer.subclasses # => ["Bignum", "Fixnum"] +C.descendants #=> [] -module M - class A; end - class B1 < A; end - class B2 < A; end -end +class B < C; end +C.descendants #=> [B] -module N - class C < M::B1; end -end +class A < B; end +C.descendants #=> [B, A] -M::A.subclasses # => ["N::C", "M::B2", "M::B1"] +class D < C; end +C.descendants #=> [B, A, D] -The order in which these class names are returned is unspecified. +h5. +subclasses+ + +The +subclasses+ method returns all direct classes that inherits from self. + + +class C; end +C.subclasses #=> [] + +class B < C; end +C.subclasses #=> [B] + +class A < B; end +C.subclasses #=> [B] + +class D < C; end +C.subclasses #=> [B, D] + -See also +Object#subclasses_of+ in "Extensions to All Objects FIX THIS LINK":FIXME. +The order in which these class are returned is unspecified. -WARNING: This method is redefined in some Rails core classes. +WARNING: This method is redefined in some Rails core classes but should be all compatible in Rails 3.1. NOTE: Defined in +active_support/core_ext/class/subclasses.rb+. -- cgit v1.2.3 From db0530e4ba48f20cd42b781d053cdb23e5e7d210 Mon Sep 17 00:00:00 2001 From: Mark Hayes Date: Mon, 5 Jul 2010 19:28:58 -0700 Subject: Fixed typo in Rails::Generators::Base [#5051 state:resolved] --- railties/lib/rails/generators/actions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index 199afbdc30..a27d38e23a 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -267,7 +267,7 @@ module Rails ActiveSupport::Deprecation.warn "freeze! is deprecated since your rails app now comes bundled with Rails by default, please check your Gemfile" end - # Make an entry in Rails routing file conifg/routes.rb + # Make an entry in Rails routing file config/routes.rb # # === Example # -- cgit v1.2.3 From e5c95b1871da61984b4cd109e39b605c447323dd Mon Sep 17 00:00:00 2001 From: l4u Date: Tue, 6 Jul 2010 21:15:14 +0800 Subject: Fixed minor typo app/view to app/views --- railties/guides/source/getting_started.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 6abb3ed9f4..f547f29087 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -958,7 +958,7 @@ You'll see a bit more complexity here than you did in the controller for posts. In addition, the code takes advantage of some of the methods available for an association. We use the +create+ method on +@post.comments+ to create and save the comment. This will automatically link the comment so that it belongs to that particular post. -Once we have made the new comment, we send the user back to the original post using the +post_path(@post)+ helper. As we have already seen, this calls the +show+ action of the +PostsController+ which in turn renders the +show.html.erb+ template. This is where we want the comment to show, so let's add that to the +app/view/posts/show.html.erb+. +Once we have made the new comment, we send the user back to the original post using the +post_path(@post)+ helper. As we have already seen, this calls the +show+ action of the +PostsController+ which in turn renders the +show.html.erb+ template. This is where we want the comment to show, so let's add that to the +app/views/posts/show.html.erb+.

<%= notice %>

-- cgit v1.2.3 From 92ff71bb14b1b589a3d5c04d120e4b9210b243b1 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 6 Jul 2010 17:29:19 +0200 Subject: documents automatic management of join models in hmt associations, in particular the gotcha that deletion is direct --- railties/guides/source/association_basics.textile | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile index 335d17579d..c69f2ae8c9 100644 --- a/railties/guides/source/association_basics.textile +++ b/railties/guides/source/association_basics.textile @@ -137,6 +137,16 @@ end !images/has_many_through.png(has_many :through Association Diagram)! +The collection of join models can be managed via the API. For example, if you assign + + +physician.patients = patients + + +new join models are created for newly associated objects, and if some are gone their rows are deleted. + +WARNING: Automatic deletion of join models is direct, no destroy callbacks are triggered. + The +has_many :through+ association is also useful for setting up "shortcuts" through nested +has_many+ associations. For example, if a document has many sections, and a section has many paragraphs, you may sometimes want to get a simple collection of all paragraphs in the document. You could set that up this way: -- cgit v1.2.3 From 0f96cea322294f84df34c43000443b249a880126 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 7 Jul 2010 05:31:54 +0100 Subject: Add note about incompatibility of namespace and :controller --- railties/guides/source/routing.textile | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile index 00755071c5..72a76e25bb 100644 --- a/railties/guides/source/routing.textile +++ b/railties/guides/source/routing.textile @@ -382,6 +382,12 @@ match ':controller/:action/:id/:user_id' An incoming URL of +/photos/show/1/2+ will be dispatched to the +show+ action of the +PhotosController+. +params[:id]+ will be +"1"+, and +params[:user_id]+ will be +"2"+. +NOTE: You can't use +namespace+ or +:module+ with a +:controller+ path segment. If you need to do this then use a constraint on :controller that matches the namespace you require. e.g: + + +match ':controller(/:action(/:id))', :controller => /admin\/[^\/]+/ + + h4. Static Segments You can specify static segments when creating a route: -- cgit v1.2.3 From 8735d15e61797d0e6879efbde4f1ca18b4403eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 7 Jul 2010 12:50:38 +0200 Subject: Add a test to ensure url helpers are not action methods in ActionMailer. --- .../test/application/initializers/frameworks_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'railties') diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index b1deb7a645..4ff10091b1 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -45,6 +45,25 @@ module ApplicationTests assert_equal "test.rails", ActionMailer::Base.default_url_options[:host] end + test "does not include url helpers as action methods" do + app_file "config/routes.rb", <<-RUBY + AppTemplate::Application.routes.draw do + get "/foo", :to => lambda { |env| [200, {}, []] }, :as => :foo + end + RUBY + + app_file "app/mailers/foo.rb", <<-RUBY + class Foo < ActionMailer::Base + def notify + end + end + RUBY + + require "#{app_path}/config/environment" + assert Foo.method_defined?(:foo_path) + assert_equal ["notify"], Foo.action_methods + end + # AS test "if there's no config.active_support.bare, all of ActiveSupport is required" do use_frameworks [] -- cgit v1.2.3 From ff44cc284441be894cc6f2bbc1798a21e881414e Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sun, 4 Jul 2010 17:20:50 +0900 Subject: whitespace Signed-off-by: Jeremy Kemper --- railties/lib/rails/commands/plugin.rb | 97 +++++++++++++++++------------------ 1 file changed, 47 insertions(+), 50 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/commands/plugin.rb b/railties/lib/rails/commands/plugin.rb index 8bcd92a33b..e0930cdcee 100644 --- a/railties/lib/rails/commands/plugin.rb +++ b/railties/lib/rails/commands/plugin.rb @@ -3,7 +3,7 @@ # Installing plugins: # # $ rails plugin install continuous_builder asset_timestamping -# +# # Specifying revisions: # # * Subversion revision is a single integer. @@ -14,12 +14,11 @@ # 'tag 1.8.0' (equivalent to 'refs/tags/1.8.0') # # -# This is Free Software, copyright 2005 by Ryan Tomayko (rtomayko@gmail.com) +# This is Free Software, copyright 2005 by Ryan Tomayko (rtomayko@gmail.com) # and is licensed MIT: (http://www.opensource.org/licenses/mit-license.php) $verbose = false - require 'open-uri' require 'fileutils' require 'tempfile' @@ -40,18 +39,18 @@ class RailsEnvironment dir = File.dirname(dir) end end - + def self.default @default ||= find end - + def self.default=(rails_env) @default = rails_env end - + def install(name_uri_or_plugin) if name_uri_or_plugin.is_a? String - if name_uri_or_plugin =~ /:\/\// + if name_uri_or_plugin =~ /:\/\// plugin = Plugin.new(name_uri_or_plugin) else plugin = Plugins[name_uri_or_plugin] @@ -65,7 +64,7 @@ class RailsEnvironment puts "Plugin not found: #{name_uri_or_plugin}" end end - + def use_svn? require 'active_support/core_ext/kernel' silence_stderr {`svn --version` rescue nil} @@ -97,7 +96,7 @@ class RailsEnvironment ext = `svn propget svn:externals "#{root}/vendor/plugins"` lines = ext.respond_to?(:lines) ? ext.lines : ext lines.reject{ |line| line.strip == '' }.map do |line| - line.strip.split(/\s+/, 2) + line.strip.split(/\s+/, 2) end end @@ -111,38 +110,37 @@ class RailsEnvironment system("svn propset -q svn:externals -F \"#{file.path}\" \"#{root}/vendor/plugins\"") end end - end class Plugin attr_reader :name, :uri - + def initialize(uri, name = nil) @uri = uri guess_name(uri) end - + def self.find(name) new(name) end - + def to_s "#{@name.ljust(30)}#{@uri}" end - + def svn_url? @uri =~ /svn(?:\+ssh)?:\/\/*/ end - + def git_url? @uri =~ /^git:\/\// || @uri =~ /\.git$/ end - + def installed? File.directory?("#{rails_env.root}/vendor/plugins/#{name}") \ or rails_env.externals.detect{ |name, repo| self.uri == repo } end - + def install(method=nil, options = {}) method ||= rails_env.best_install_method? if :http == method @@ -173,7 +171,7 @@ class Plugin if rails_env.use_externals? # clean up svn:externals externals = rails_env.externals - externals.reject!{|n,u| name == n or name == u} + externals.reject!{|n, u| name == n or name == u} rails_env.externals = externals end end @@ -192,7 +190,7 @@ class Plugin FileUtils.rm_rf tmp if svn_url? end - private + private def run_install_hook install_hook_file = "#{rails_env.root}/vendor/plugins/#{name}/install.rb" @@ -207,11 +205,11 @@ class Plugin def install_using_export(options = {}) svn_command :export, options end - + def install_using_checkout(options = {}) svn_command :checkout, options end - + def install_using_externals(options = {}) externals = rails_env.externals externals.push([@name, uri]) @@ -229,7 +227,7 @@ class Plugin fetcher.fetch end end - + def install_using_git(options = {}) root = rails_env.root mkdir_p(install_path = "#{root}/vendor/plugins/#{name}") @@ -268,7 +266,7 @@ class Plugin end @name.gsub!(/\.git$/, '') if @name =~ /\.git$/ end - + def rails_env @rails_env || RailsEnvironment.default end @@ -277,45 +275,44 @@ end # load default environment and parse arguments require 'optparse' module Commands - class Plugin attr_reader :environment, :script_name, :sources def initialize @environment = RailsEnvironment.default @rails_root = RailsEnvironment.default.root - @script_name = File.basename($0) + @script_name = File.basename($0) @sources = [] end - + def environment=(value) @environment = value RailsEnvironment.default = value end - + def options OptionParser.new do |o| o.set_summary_indent(' ') o.banner = "Usage: plugin [OPTIONS] command" o.define_head "Rails plugin manager." - - o.separator "" + + o.separator "" o.separator "GENERAL OPTIONS" - + o.on("-r", "--root=DIR", String, "Set an explicit rails app directory.", "Default: #{@rails_root}") { |rails_root| @rails_root = rails_root; self.environment = RailsEnvironment.new(@rails_root) } o.on("-s", "--source=URL1,URL2", Array, "Use the specified plugin repositories instead of the defaults.") { |sources| @sources = sources} - + o.on("-v", "--verbose", "Turn on verbose output.") { |verbose| $verbose = verbose } o.on("-h", "--help", "Show this help message.") { puts o; exit } - + o.separator "" o.separator "COMMANDS" - + o.separator " install Install plugin(s) from known repositories or URLs." o.separator " remove Uninstall plugins." - + o.separator "" o.separator "EXAMPLES" o.separator " Install a plugin:" @@ -328,11 +325,11 @@ module Commands o.separator " #{@script_name} plugin install -x continuous_builder\n" end end - + def parse!(args=ARGV) general, sub = split_args(args) options.parse!(general) - + command = general.shift if command =~ /^(install|remove)$/ command = Commands.const_get(command.capitalize).new(self) @@ -343,26 +340,26 @@ module Commands exit 1 end end - + def split_args(args) left = [] left << args.shift while args[0] and args[0] =~ /^-/ left << args.shift if args[0] return [left, args] end - + def self.parse!(args=ARGV) Plugin.new.parse!(args) end end - + class Install def initialize(base_command) @base_command = base_command @method = :http @options = { :quiet => false, :revision => nil, :force => false } end - + def options OptionParser.new do |o| o.set_summary_indent(' ') @@ -370,8 +367,8 @@ module Commands o.define_head "Install one or more plugins." o.separator "" o.separator "Options:" - o.on( "-x", "--externals", - "Use svn:externals to grab the plugin.", + o.on( "-x", "--externals", + "Use svn:externals to grab the plugin.", "Enables plugin updates and plugin versioning.") { |v| @method = :externals } o.on( "-o", "--checkout", "Use svn checkout to grab the plugin.", @@ -392,7 +389,7 @@ module Commands o.separator "a plugin repository." end end - + def determine_install_method best = @base_command.environment.best_install_method @method = :http if best == :http and @method == :export @@ -410,7 +407,7 @@ module Commands end @method end - + def parse!(args) options.parse!(args) environment = @base_command.environment @@ -430,7 +427,7 @@ module Commands def initialize(base_command) @base_command = base_command end - + def options OptionParser.new do |o| o.set_summary_indent(' ') @@ -438,7 +435,7 @@ module Commands o.define_head "Remove plugins." end end - + def parse!(args) options.parse!(args) root = @base_command.environment.root @@ -470,7 +467,7 @@ module Commands end end end - + class RecursiveHTTPFetcher attr_accessor :quiet def initialize(urls_to_fetch, level = 1, cwd = ".") @@ -511,7 +508,7 @@ class RecursiveHTTPFetcher end links end - + def download(link) puts "+ #{File.join(@cwd, File.basename(link))}" unless @quiet open(link) do |stream| @@ -520,13 +517,13 @@ class RecursiveHTTPFetcher end end end - + def fetch(links = @urls_to_fetch) links.each do |l| (l =~ /\/$/ || links == @urls_to_fetch) ? fetch_dir(l) : download(l) end end - + def fetch_dir(url) @level += 1 push_d(File.basename(url)) if @level > 0 -- cgit v1.2.3 From bf5d15456757e63598575db42917d702af9da729 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sun, 4 Jul 2010 17:37:57 +0900 Subject: Print proper "Usage:" messages for "rails plugin" command * suppress outputting "Unknown command:" when no command were specified * output the "Usage:" message when no plugin names were given [#5043 state:committed] Signed-off-by: Jeremy Kemper --- railties/lib/rails/commands/plugin.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/commands/plugin.rb b/railties/lib/rails/commands/plugin.rb index e0930cdcee..96b6f9c372 100644 --- a/railties/lib/rails/commands/plugin.rb +++ b/railties/lib/rails/commands/plugin.rb @@ -335,7 +335,7 @@ module Commands command = Commands.const_get(command.capitalize).new(self) command.parse!(sub) else - puts "Unknown command: #{command}" + puts "Unknown command: #{command}" unless command.blank? puts options exit 1 end @@ -345,7 +345,7 @@ module Commands left = [] left << args.shift while args[0] and args[0] =~ /^-/ left << args.shift if args[0] - return [left, args] + [left, args] end def self.parse!(args=ARGV) @@ -410,6 +410,10 @@ module Commands def parse!(args) options.parse!(args) + if args.blank? + puts options + exit 1 + end environment = @base_command.environment install_method = determine_install_method puts "Plugins will be installed using #{install_method}" if $verbose @@ -438,6 +442,10 @@ module Commands def parse!(args) options.parse!(args) + if args.blank? + puts options + exit 1 + end root = @base_command.environment.root args.each do |name| ::Plugin.new(name).uninstall -- cgit v1.2.3 From a9587935dec6b5de01d51553ecc6d4157a8ec173 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 8 Jul 2010 16:53:37 +0200 Subject: copy-edits some docs --- .../source/active_support_core_extensions.textile | 36 ++++++++++++---------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index de0c00ac68..58824d7aeb 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1107,47 +1107,51 @@ If for whatever reason an application loads the definition of a mailer class and NOTE: Defined in +active_support/core_ext/class/delegating_attributes.rb+. -h4. Descendants & Subclasses +h4. Subclasses & Descendants -h5. +descendants+ +h5. +subclasses+ -The +descendants+ method returns all classes, including its children, that inherits from self. +The +subclasses+ method returns the subclasses of the receiver: class C; end -C.descendants #=> [] +C.subclasses # => [] class B < C; end -C.descendants #=> [B] +C.subclasses # => [B] class A < B; end -C.descendants #=> [B, A] +C.subclasses # => [B] class D < C; end -C.descendants #=> [B, A, D] +C.subclasses # => [B, D] -h5. +subclasses+ +The order in which these classes are returned is unspecified. -The +subclasses+ method returns all direct classes that inherits from self. +WARNING: This method is redefined in some Rails core classes but should be all compatible in Rails 3.1. + +NOTE: Defined in +active_support/core_ext/class/subclasses.rb+. + +h5. +descendants+ + +The +descendants+ method returns all classes that are < than its receiver: class C; end -C.subclasses #=> [] +C.descendants # => [] class B < C; end -C.subclasses #=> [B] +C.descendants # => [B] class A < B; end -C.subclasses #=> [B] +C.descendants # => [B, A] class D < C; end -C.subclasses #=> [B, D] +C.descendants # => [B, A, D] -The order in which these class are returned is unspecified. - -WARNING: This method is redefined in some Rails core classes but should be all compatible in Rails 3.1. +The order in which these classes are returned is unspecified. NOTE: Defined in +active_support/core_ext/class/subclasses.rb+. -- cgit v1.2.3 From e848ab527ca9da1a6cf2a8485163f01daf3f66d1 Mon Sep 17 00:00:00 2001 From: Sudara Date: Fri, 2 Jul 2010 00:20:26 +0000 Subject: Allow a PID file to be specified to rails server [#5031 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- railties/lib/rails/commands/server.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index 9d9dd48ea9..c3927b6613 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -21,6 +21,9 @@ module Rails opts.on("-e", "--environment=name", String, "Specifies the environment to run this server under (test/development/production).", "Default: development") { |v| options[:environment] = v } + opts.on("-P","--pid=pid",String, + "Specifies the PID file.", + "Default: tmp/pids/server.pid") { |v| options[:pid] = v } opts.separator "" -- cgit v1.2.3 From d7ffa3c077e08921ea7897455084fc2942fe0977 Mon Sep 17 00:00:00 2001 From: Norman Clarke Date: Thu, 8 Jul 2010 17:43:08 -0300 Subject: Describe recent changes in Multibyte::Chars. --- railties/guides/source/initialization.textile | 137 +++++++++++++++----------- 1 file changed, 81 insertions(+), 56 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 9a0e23385d..7a44ef7c77 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -3568,28 +3568,24 @@ h3. Appendix A This file is _activesupport/lib/active_support/inflector/inflections.rb_ and defines the +ActiveSupport::Inflector::Inflections+ class which defines the +singularize+, +pluralize+, +humanize+, +tableize+, +titleize+ and +classify+ methods as well as the code to defining how to work out the irregular, singular, plural and human versions of words. These methods are called +irregular+, +singular+, +plural+ and +human+ respectively, as is the Rails way. -This file is _activesupport/lib/active_support/inflector/transliterate.rb_ and defines two methods, +transliterate+ and +parameterize+. What +transliterate+ does depends on your Ruby version. If you have something greater than 1.9 installed it will just print out a warning message using the +Kernel#warn+ method (simply called using +warn+) reading "Ruby 1.9 doesn't support Unicode normalization yet". If you're running something that's not 1.9 it will attempt to convert +"föö"+ to +foo+ and if that fails then it'll redefine it. +This file is _activesupport/lib/active_support/inflector/transliterate.rb_ and defines two methods, +transliterate+ and +parameterize+. -This file first makes a require to _activesupport/lib/active_support/core_ext/string/multibyte.rb_ which then goes on to require _activesupport/lib/active_support/multibyte.rb_ and that requires _activesupport/core_ext/module/attribute_accessors.rb_. The _attribute_accessors.rb_ file is used to gain access to the +mattr_accessor+ (module attribute accessor) method which is called in _active_suport/multibyte.rb_. Also in _active_support/multibyte.rb_ there's a couple of autoloaded classes: +This file first requires _activesupport/lib/active_support/core_ext/string/multibyte.rb_, which requires _activesupport/lib/active_support/multibyte.rb_, which subsequently requires _activesupport/core_ext/module/attribute_accessors.rb_. The _attribute_accessors.rb_ file is needed to gain access to the +mattr_accessor+ (module attribute accessor) method, which is called in _active_suport/multibyte.rb_. The file _active_support/multibyte.rb_ also autoloads three other classes: module ActiveSupport #:nodoc: module Multibyte autoload :EncodingError, 'active_support/multibyte/exceptions' autoload :Chars, 'active_support/multibyte/chars' - autoload :UnicodeDatabase, 'active_support/multibyte/unicode_database' - autoload :Codepoint, 'active_support/multibyte/unicode_database' - autoload :UCD, 'active_support/multibyte/unicode_database' - ... + autoload :Unicode, 'active_support/multibyte/unicode' + ... end end -There's also these method definitions: +There are also these method definitions: - self.default_normalization_form = :kc - # The proxy class returned when calling mb_chars. You can use this accessor to configure your own proxy # class so you can support other encodings. See the ActiveSupport::Multibyte::Chars implementation for # an example how to do this. @@ -3608,63 +3604,92 @@ There's also these method definitions: These methods are used in _activesupport/lib/active_support/core_ext/string/multibyte.rb_. -If we go back to _activesupport/lib/active_support/core_ext/string/multibyte.rb_, this file makes a couple of extensions to the +String+ class based on if your version of Ruby's +String+ class responds to the +force_encoding+ method. This method was introduced in Ruby 1.9. If you're using 1.9 the methods are defined like this: - - - def mb_chars #:nodoc - self - end - - def is_utf8? #:nodoc - case encoding - when Encoding::UTF_8 - valid_encoding? - when Encoding::ASCII_8BIT, Encoding::US_ASCII - dup.force_encoding(Encoding::UTF_8).valid_encoding? - else - false - end - end - - -You can see that calling +mb_chars+ on a +String+ instance in Ruby 1.9 will simply return that +String+ object. +String+ objects in Ruby 1.9 are already multibyte strings, so Rails does not need to do any conversion on them. - -The second method, +is_utf8?+ return +true+ if the +String+ object is of the UTF8 encoding or if it's able to be forced into that encoding and +false+ if it can't force its encoding or if the encoding of the string is neither +UTF8+, +ASCII_8BIT+ or +US_ASCII+. - -If you're using a Ruby version less than 1.9 there are 3 methods defined instead of 2, and they are defined like this: +The file _activesupport/lib/active_support/core_ext/string/chars.rb_ defines the default proxy class that will be returned by +mb_chars+. + +Because Ruby 1.9's +String+ class has support for multibyte encodings, some methods are defined only for Ruby 1.8: + +* +self.wants?+ +* +++ +* +=~+ +* +=~+ +* +center+ +* +include?+ +* +index+ +* +insert+ +* +ljust+ +* +lstrip+, +lstrip!+ +* +ord+ +* +rindex+ +* +rjust+ +* +rstrip+, +rstrip!+ +* +size+ +* +strip+, +strip!+ + +However, Ruby 1.9 lacks support for some needed operations, so the following methods are defined for both Ruby 1.8 and Ruby 1.9: + +* +<=>+ +* +[]=+ +* +capitalize+, +capitalize!+ +* +compose+ +* +decompose+ +* +downcase+, +downcase!+ +* +g_length+ +* +limit+ +* +normalize+ +* +reverse+, +reverse+! +* +slice+, +slice!+ +* +split+ +* +tidy_bytes+, +tidy_bytes!+ +* +titleize+ +* +upcase+, +upcase!+ + + + class String + if RUBY_VERSION >= "1.9" + def mb_chars + if ActiveSupport::Multibyte.proxy_class.consumes?(self) + ActiveSupport::Multibyte.proxy_class.new(self) + else + self + end + end - - def mb_chars - if ActiveSupport::Multibyte.proxy_class.wants?(self) - ActiveSupport::Multibyte.proxy_class.new(self) + def is_utf8? #:nodoc + case encoding + when Encoding::UTF_8 + valid_encoding? + when Encoding::ASCII_8BIT, Encoding::US_ASCII + dup.force_encoding(Encoding::UTF_8).valid_encoding? + else + false + end + end else - self - end - end - - # Returns true if the string has UTF-8 semantics (a String used for purely byte resources is unlikely to have - # them), returns false otherwise. - def is_utf8? - ActiveSupport::Multibyte::Chars.consumes?(self) - end + def mb_chars + if ActiveSupport::Multibyte.proxy_class.wants?(self) + ActiveSupport::Multibyte.proxy_class.new(self) + else + self + end + end - unless '1.8.7 and later'.respond_to?(:chars) - def chars - ActiveSupport::Deprecation.warn('String#chars has been deprecated in favor of String#mb_chars.', caller) - mb_chars + # Returns true if the string has UTF-8 semantics (a String used for purely byte resources is unlikely to have + # them), returns false otherwise. + def is_utf8? + ActiveSupport::Multibyte::Chars.consumes?(self) + end end - end - +As you can see, +mb_chars+ is where the +proxy_class+ property comes in handy. This method will create a new instance of the configured proxy class using the instance of +String+ as a constructor argument. By default, the new +String+-like object will be an instance of the proxy class +ActiveSupport::Multibyte::Chars+. You can use +ActiveSupport::Multibyte.proxy_class=+ to set a different proxy class if you wish. -As you can see, +mb_chars+ is where the +proxy_class+ method comes in handy. This will create a new instance of that class and pass in the +String+ object in order to make it multibyte-compatible. In this case the new +String+ object will be an instance of the +ActiveSupport::Multibyte::Chars+ class. You can use +ActiveSupport::Multibyte.proxy_class=+ to set this to be a different class if you're that way inclined. - -Here, +is_utf8?+ calls a +consumes+ method on the not-yet-loaded +ActiveSupport::Multibyte::Chars+ class. The keen-eye would have seen this was specified as an auto-load earlier, so that is what is going to happen if we call this method or +mb_chars+. This means that it'll require the file located at _activesupport/lib/active_support/multibyte/chars.rb_. This file includes _activesupport/lib/active_support/string/access.rb_ which defines methods such as +at+, +from+, +to+, +first+ and +last+. These methods will return parts of the string depending on what is passed to them and they are defined differently depending on if you're using Ruby 1.9 or not. The second file included is _activesupport/lib/active_support/string/behaviour.rb_ which defines a single method +acts_like_string?+ on +String+ which always returns +true+. This method is used through the +acts_like?+ method which is passed a single argument representing the downcased and symbolised version of the class you want to know if it acts like. In this case the code would be +acts_like?(:string)+. +Here, +mb_chars+ invokes +is_utf8?+ to checks if the string can be treated as UTF-8. On 1.9, the string's +encoding+ property is checked. On 1.8, +wants?+ checks to see if +$KCODE+ is "UTF-8" and, and +consumes?+ checks whether the string can be unpacked as UTF-8 without raising an error. -The +Chars+ class defines, along with +consumes?+, other methods such as the "spaceship" method +<=>+. This method is referenced by the methods defined in the included +Comparable+ module and will return either +-1+, +0+ or +1+ depending on if the word is before, identical or after the compared word. For example, +'é'.mb_chars <=> 'ü'.mb_chars+ returns +-1+ as e comes before u in the alphabet. Other methods are the commonly used +split+, +=~+, +insert+ and +include?+. +The keen eye will have seen +ActiveSupport::Multibyte::Chars+ was specified as an +autoload+ earlier: _activesupport/lib/active_support/multibyte/chars.rb_ will be loaded without an explicit +require+ when we call +is_utf8+ on 1.8, or +mb_chars+ on any Ruby version. This file includes _activesupport/lib/active_support/string/access.rb_ which defines methods such as +at+, +from+, +to+, +first+ and +last+. These methods will return parts of the string depending on what is passed to them. +The second file included is _activesupport/lib/active_support/string/behavior.rb_ which only defines +acts_like_string?+ on +String+, a method which always returns +true+. This method is used by +Object#acts_like?+, which accepts a single argument representing the downcased and symbolised version of a class, and returns true if the object's behavior is like that class. In this case the code would be +acts_like?(:string)+. +The +Chars+ class also defines other important methods such as the "spaceship" method +<=>+, which is needed by the +Comparable+ module, in order to allow UTF-8-aware sorting. h3. Common Includes -- cgit v1.2.3 From c6f4c5916ef467814d970c70627a82c1df4d2686 Mon Sep 17 00:00:00 2001 From: Jaime Iniesta Date: Fri, 9 Jul 2010 17:53:47 +0200 Subject: Minor typos: 'built-in' instead of 'built in', 'built into' instead of 'built in to' --- railties/guides/source/index.html.erb | 2 +- railties/guides/source/layouts_and_rendering.textile | 2 +- railties/guides/source/plugins.textile | 2 +- railties/guides/source/security.textile | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/index.html.erb b/railties/guides/source/index.html.erb index be077fcd2f..a930db0f1d 100644 --- a/railties/guides/source/index.html.erb +++ b/railties/guides/source/index.html.erb @@ -68,7 +68,7 @@ Ruby on Rails Guides <% end %> <%= guide("Action View Form Helpers", 'form_helpers.html', :ticket => 1) do %> -

Guide to using built in Form helpers.

+

Guide to using built-in Form helpers.

<% end %> diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile index a874fa0ca7..f4ba6dd53b 100644 --- a/railties/guides/source/layouts_and_rendering.textile +++ b/railties/guides/source/layouts_and_rendering.textile @@ -2,7 +2,7 @@ h2. Layouts and Rendering in Rails This guide covers the basic layout features of Action Controller and Action View. By referring to this guide, you will be able to: -* Use the various rendering methods built in to Rails +* Use the various rendering methods built into Rails * Create layouts with multiple content sections * Use partials to DRY up your views * Use nested layouts (sub-templates) diff --git a/railties/guides/source/plugins.textile b/railties/guides/source/plugins.textile index a12434a95b..e853ba79e9 100644 --- a/railties/guides/source/plugins.textile +++ b/railties/guides/source/plugins.textile @@ -1284,7 +1284,7 @@ class YaffleMigrationGenerator < Rails::Generator::NamedBase end
-The generator creates a new file in 'db/migrate' with a timestamp and an 'add_column' statement. It reuses the built in rails +migration_template+ method, and reuses the built-in rails migration template. +The generator creates a new file in 'db/migrate' with a timestamp and an 'add_column' statement. It reuses the built-in rails +migration_template+ method, and reuses the built-in rails migration template. It's courteous to check to see if table names are being pluralized whenever you create a generator that needs to be aware of table names. This way people using your generator won't have to manually change the generated files if they've turned pluralization off. diff --git a/railties/guides/source/security.textile b/railties/guides/source/security.textile index b45514f66d..60108d5ab3 100644 --- a/railties/guides/source/security.textile +++ b/railties/guides/source/security.textile @@ -670,7 +670,7 @@ Also, the second query renames some columns with the AS statement so that the we h5(#sql-injection-countermeasures). Countermeasures -Ruby on Rails has a built in filter for special SQL characters, which will escape ' , " , NULL character and line breaks. Using +Model.find(id)+ or +Model.find_by_some thing(something)+ automatically applies this countermeasure. But in SQL fragments, especially in conditions fragments (+:conditions => "..."+), the +connection.execute()+ or +Model.find_by_sql()+ methods, it has to be applied manually. +Ruby on Rails has a built-in filter for special SQL characters, which will escape ' , " , NULL character and line breaks. Using +Model.find(id)+ or +Model.find_by_some thing(something)+ automatically applies this countermeasure. But in SQL fragments, especially in conditions fragments (+:conditions => "..."+), the +connection.execute()+ or +Model.find_by_sql()+ methods, it has to be applied manually. Instead of passing a string to the conditions option, you can pass an array to sanitize tainted strings like this: -- cgit v1.2.3 From c9ae2c11ebbf42d887dced2938a59e8d0634d60a Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Fri, 9 Jul 2010 19:09:47 +0200 Subject: application.rb: revises the comment for autoload_paths so that is assumes less from the user, and unifies punctuation --- .../lib/rails/generators/rails/app/templates/config/application.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index 031466cb86..67a38ea1d5 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -21,14 +21,14 @@ module <%= app_const_base %> # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. - # Add additional load paths for your own custom dirs + # Custom directories with classes and modules you want to be autoloadable. # config.autoload_paths += %W( #{config.root}/extras ) # Only load the plugins named here, in the order given (default is alphabetical). - # :all can be used as a placeholder for all plugins not explicitly named + # :all can be used as a placeholder for all plugins not explicitly named. # config.plugins = [ :exception_notification, :ssl_requirement, :all ] - # Activate observers that should always be running + # Activate observers that should always be running. # config.active_record.observers = :cacher, :garbage_collector, :forum_observer # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. -- cgit v1.2.3