railties 3.1.0.rc1 → 3.1.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/CHANGELOG +2 -0
  2. data/guides/assets/images/radar.png +0 -0
  3. data/guides/assets/images/vijaydev.jpg +0 -0
  4. data/guides/rails_guides/helpers.rb +1 -1
  5. data/guides/source/action_view_overview.textile +6 -103
  6. data/guides/source/active_record_basics.textile +2 -2
  7. data/guides/source/active_record_querying.textile +32 -4
  8. data/guides/source/active_record_validations_callbacks.textile +5 -3
  9. data/guides/source/active_support_core_extensions.textile +4 -4
  10. data/guides/source/api_documentation_guidelines.textile +2 -2
  11. data/guides/source/caching_with_rails.textile +5 -5
  12. data/guides/source/command_line.textile +78 -71
  13. data/guides/source/configuring.textile +90 -74
  14. data/guides/source/contribute.textile +2 -2
  15. data/guides/source/contributing_to_ruby_on_rails.textile +3 -3
  16. data/guides/source/credits.html.erb +16 -8
  17. data/guides/source/generators.textile +3 -3
  18. data/guides/source/getting_started.textile +1 -1
  19. data/guides/source/i18n.textile +1 -1
  20. data/guides/source/initialization.textile +311 -310
  21. data/guides/source/migrations.textile +4 -4
  22. data/guides/source/rails_on_rack.textile +6 -6
  23. data/guides/source/routing.textile +1 -1
  24. data/guides/source/testing.textile +2 -2
  25. data/lib/rails/application.rb +17 -12
  26. data/lib/rails/commands.rb +1 -1
  27. data/lib/rails/commands/benchmarker.rb +3 -3
  28. data/lib/rails/commands/console.rb +2 -1
  29. data/lib/rails/commands/profiler.rb +3 -3
  30. data/lib/rails/commands/server.rb +2 -1
  31. data/lib/rails/configuration.rb +6 -0
  32. data/lib/rails/engine.rb +1 -1
  33. data/lib/rails/generators.rb +8 -2
  34. data/lib/rails/generators/css/assets/assets_generator.rb +13 -0
  35. data/lib/rails/generators/{rails/assets/templates/stylesheet.css.scss → css/assets/templates/stylesheet.css} +1 -2
  36. data/lib/rails/generators/css/scaffold/scaffold_generator.rb +16 -0
  37. data/lib/rails/generators/rails/app/app_generator.rb +1 -1
  38. data/lib/rails/generators/rails/app/templates/Gemfile +2 -2
  39. data/lib/rails/generators/rails/app/templates/config/application.rb +0 -11
  40. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +3 -0
  41. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +4 -2
  42. data/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +2 -2
  43. data/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb +1 -1
  44. data/lib/rails/generators/rails/assets/USAGE +1 -1
  45. data/lib/rails/generators/rails/assets/assets_generator.rb +2 -9
  46. data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +3 -3
  47. data/lib/rails/generators/rails/plugin_new/templates/Rakefile +8 -3
  48. data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +2 -11
  49. data/lib/rails/generators/test_unit/performance/templates/performance_test.rb +1 -1
  50. data/lib/rails/railtie.rb +7 -7
  51. data/lib/rails/railtie/configurable.rb +2 -0
  52. data/lib/rails/tasks/assets.rake +12 -1
  53. data/lib/rails/tasks/documentation.rake +8 -2
  54. data/lib/rails/tasks/misc.rake +1 -1
  55. data/lib/rails/version.rb +1 -1
  56. metadata +56 -9
  57. data/lib/rails/generators/rails/scaffold/templates/scaffold.css.scss +0 -58
@@ -55,6 +55,8 @@ class AddReceiveNewsletterToUsers < ActiveRecord::Migration
55
55
  end
56
56
  </ruby>
57
57
 
58
+ NOTE: Some "caveats":#using-models-in-your-migrations apply to using models in your migrations.
59
+
58
60
  This migration adds a +receive_newsletter+ column to the +users+ table. We want it to default to +false+ for new users, but existing users are considered
59
61
  to have already opted in, so we use the User model to set the flag to +true+ for existing users.
60
62
 
@@ -73,11 +75,9 @@ class CreateProducts < ActiveRecord::Migration
73
75
  end
74
76
  </ruby>
75
77
 
76
- NOTE: Some "caveats":#using-models-in-your-migrations apply to using models in your migrations.
77
-
78
78
  h4. Migrations are Classes
79
79
 
80
- A migration is a subclass of <tt>ActiveRecord::Migration</tt> that implements two class methods: +up+ (perform the required transformations) and +down+ (revert them).
80
+ A migration is a subclass of <tt>ActiveRecord::Migration</tt> that implements two methods: +up+ (perform the required transformations) and +down+ (revert them).
81
81
 
82
82
  Active Record provides methods that perform common data definition tasks in a database independent way (you'll read about them in detail later):
83
83
 
@@ -115,7 +115,7 @@ h4. Changing Migrations
115
115
 
116
116
  Occasionally you will make a mistake when writing a migration. If you have already run the migration then you cannot just edit the migration and run the migration again: Rails thinks it has already run the migration and so will do nothing when you run +rake db:migrate+. You must rollback the migration (for example with +rake db:rollback+), edit your migration and then run +rake db:migrate+ to run the corrected version.
117
117
 
118
- In general editing existing migrations is not a good idea: you will be creating extra work for yourself and your co-workers and cause major headaches if the existing version of the migration has already been run on production machines. Instead you should write a new migration that performs the changes you require. Editing a freshly generated migration that has not yet been committed to source control (or more generally which has not been propagated beyond your development machine) is relatively harmless. Just use some common sense.
118
+ In general editing existing migrations is not a good idea: you will be creating extra work for yourself and your co-workers and cause major headaches if the existing version of the migration has already been run on production machines. Instead you should write a new migration that performs the changes you require. Editing a freshly generated migration that has not yet been committed to source control (or more generally which has not been propagated beyond your development machine) is relatively harmless.
119
119
 
120
120
  h3. Creating a Migration
121
121
 
@@ -111,11 +111,11 @@ h5. Adding a Middleware
111
111
 
112
112
  You can add a new middleware to the middleware stack using any of the following methods:
113
113
 
114
- * +config.middleware.use(new_middleware, args)+ - Adds the new middleware at the bottom of the middleware stack.
114
+ * <tt>config.middleware.use(new_middleware, args)</tt> - Adds the new middleware at the bottom of the middleware stack.
115
115
 
116
- * +config.middleware.insert_before(existing_middleware, new_middleware, args)+ - Adds the new middleware before the specified existing middleware in the middleware stack.
116
+ * <tt>config.middleware.insert_before(existing_middleware, new_middleware, args)</tt> - Adds the new middleware before the specified existing middleware in the middleware stack.
117
117
 
118
- * +config.middleware.insert_after(existing_middleware, new_middleware, args)+ - Adds the new middleware after the specified existing middleware in the middleware stack.
118
+ * <tt>config.middleware.insert_after(existing_middleware, new_middleware, args)</tt> - Adds the new middleware after the specified existing middleware in the middleware stack.
119
119
 
120
120
  <ruby>
121
121
  # config/environment.rb
@@ -154,20 +154,20 @@ h4. Internal Middleware Stack
154
154
  Much of Action Controller's functionality is implemented as Middlewares. The following table explains the purpose of each of them:
155
155
 
156
156
  |_.Middleware|_.Purpose|
157
- |+Rack::Lock+|Sets +env["rack.multithread"]+ flag to +true+ and wraps the application within a Mutex.|
157
+ |+Rack::Lock+|Sets <tt>env["rack.multithread"]</tt> flag to +true+ and wraps the application within a Mutex.|
158
158
  |+ActionController::Failsafe+|Returns HTTP Status +500+ to the client if an exception gets raised while dispatching.|
159
159
  |+ActiveRecord::QueryCache+|Enables the Active Record query cache.|
160
160
  |+ActionController::Session::CookieStore+|Uses the cookie based session store.|
161
161
  |+ActionController::Session::MemCacheStore+|Uses the memcached based session store.|
162
162
  |+ActiveRecord::SessionStore+|Uses the database based session store.|
163
- |+Rack::MethodOverride+|Sets HTTP method based on +_method+ parameter or +env["HTTP_X_HTTP_METHOD_OVERRIDE"]+.|
163
+ |+Rack::MethodOverride+|Sets HTTP method based on +_method+ parameter or <tt>env["HTTP_X_HTTP_METHOD_OVERRIDE"]</tt>.|
164
164
  |+Rack::Head+|Discards the response body if the client sends a +HEAD+ request.|
165
165
 
166
166
  TIP: It's possible to use any of the above middlewares in your custom Rack stack.
167
167
 
168
168
  h4. Customizing Internal Middleware Stack
169
169
 
170
- It's possible to replace the entire middleware stack with a custom stack using +ActionController::Dispatcher.middleware=+.
170
+ It's possible to replace the entire middleware stack with a custom stack using <tt>ActionController::Dispatcher.middleware=</tt>.
171
171
 
172
172
  Put the following in an initializer:
173
173
 
@@ -288,7 +288,7 @@ When using +magazine_ad_path+, you can pass in instances of +Magazine+ and +Ad+
288
288
  You can also use +url_for+ with a set of objects, and Rails will automatically determine which route you want:
289
289
 
290
290
  <erb>
291
- <%= link_to "Ad details", url_for(@magazine, @ad) %>
291
+ <%= link_to "Ad details", url_for([@magazine, @ad]) %>
292
292
  </erb>
293
293
 
294
294
  In this case, Rails will see that +@magazine+ is a +Magazine+ and +@ad+ is an +Ad+ and will therefore use the +magazine_ad_path+ helper. In helpers like +link_to+, you can specify just the object in place of the full +url_for+ call:
@@ -929,8 +929,8 @@ class UserControllerTest < ActionController::TestCase
929
929
  end
930
930
  invite_email = ActionMailer::Base.deliveries.first
931
931
 
932
- assert_equal invite_email.subject, "You have been invited by me@example.com"
933
- assert_equal invite_email.to[0], 'friend@example.com'
932
+ assert_equal "You have been invited by me@example.com", invite_email.subject
933
+ assert_equal 'friend@example.com', invite_email.to[0]
934
934
  assert_match /Hi friend@example.com/, invite_email.body
935
935
  end
936
936
  end
@@ -50,7 +50,9 @@ module Rails
50
50
  end
51
51
  end
52
52
 
53
- attr_accessor :assets
53
+ attr_accessor :assets, :sandbox
54
+ alias_method :sandbox?, :sandbox
55
+
54
56
  delegate :default_url_options, :default_url_options=, :to => :routes
55
57
 
56
58
  # This method is called just after an application inherits from Rails::Application,
@@ -96,24 +98,25 @@ module Rails
96
98
  self
97
99
  end
98
100
 
99
- def load_tasks
101
+ def load_tasks(app=self)
100
102
  initialize_tasks
101
- railties.all { |r| r.load_tasks }
103
+ railties.all { |r| r.load_tasks(app) }
102
104
  super
103
105
  self
104
106
  end
105
107
 
106
- def load_generators
108
+ def load_generators(app=self)
107
109
  initialize_generators
108
- railties.all { |r| r.load_generators }
110
+ railties.all { |r| r.load_generators(app) }
111
+
109
112
  super
110
113
  self
111
114
  end
112
115
 
113
- def load_console(sandbox=false)
114
- initialize_console(sandbox)
115
- railties.all { |r| r.load_console(sandbox) }
116
- super()
116
+ def load_console(app=self)
117
+ initialize_console
118
+ railties.all { |r| r.load_console(app) }
119
+ super
117
120
  self
118
121
  end
119
122
 
@@ -135,14 +138,16 @@ module Rails
135
138
  @config ||= Application::Configuration.new(find_root_with_flag("config.ru", Dir.pwd))
136
139
  end
137
140
 
141
+ def to_app
142
+ self
143
+ end
144
+
138
145
  protected
139
146
 
140
147
  alias :build_middleware_stack :app
141
148
 
142
149
  def default_middleware_stack
143
150
  ActionDispatch::MiddlewareStack.new.tap do |middleware|
144
- middleware.use ::Rails::Rack::ContentLength, config.action_dispatch.x_sendfile_header
145
-
146
151
  if rack_cache = config.action_controller.perform_caching && config.action_dispatch.rack_cache
147
152
  require "action_dispatch/http/rack_cache"
148
153
  middleware.use ::Rack::Cache, rack_cache
@@ -198,7 +203,7 @@ module Rails
198
203
  require "rails/generators"
199
204
  end
200
205
 
201
- def initialize_console(sandbox=false)
206
+ def initialize_console
202
207
  require "pp"
203
208
  require "rails/console/app"
204
209
  require "rails/console/helpers"
@@ -91,7 +91,7 @@ In addition to those, there are:
91
91
  benchmarker See how fast a piece of code runs
92
92
  profiler Get profile information from a piece of code
93
93
  plugin Install a plugin
94
- runner Run a piece of code in the application environment
94
+ runner Run a piece of code in the application environment (short-cut alias: "r")
95
95
 
96
96
  All commands can be run with -h for more information.
97
97
  EOT
@@ -9,7 +9,7 @@ ARGV.pop
9
9
  def options
10
10
  options = {}
11
11
  defaults = ActiveSupport::Testing::Performance::DEFAULTS
12
-
12
+
13
13
  OptionParser.new do |opt|
14
14
  opt.banner = "Usage: rails benchmarker 'Ruby.code' 'Ruby.more_code' ... [OPTS]"
15
15
  opt.on('-r', '--runs N', Numeric, 'Number of runs.', "Default: #{defaults[:runs]}") { |r| options[:runs] = r }
@@ -17,13 +17,13 @@ def options
17
17
  opt.on('-m', '--metrics a,b,c', Array, 'Metrics to use.', "Default: #{defaults[:metrics].join(",")}") { |m| options[:metrics] = m.map(&:to_sym) }
18
18
  opt.parse!(ARGV)
19
19
  end
20
-
20
+
21
21
  options
22
22
  end
23
23
 
24
24
  class BenchmarkerTest < ActionDispatch::PerformanceTest
25
25
  self.profile_options = options
26
-
26
+
27
27
  ARGV.each do |expression|
28
28
  eval <<-RUBY
29
29
  def test_#{expression.parameterize('_')}
@@ -23,7 +23,8 @@ module Rails
23
23
  opt.parse!(ARGV)
24
24
  end
25
25
 
26
- @app.load_console(options[:sandbox])
26
+ @app.sandbox = options[:sandbox]
27
+ @app.load_console
27
28
 
28
29
  if options[:debugger]
29
30
  begin
@@ -6,7 +6,7 @@ require 'active_support/testing/performance'
6
6
  def options
7
7
  options = {}
8
8
  defaults = ActiveSupport::Testing::Performance::DEFAULTS
9
-
9
+
10
10
  OptionParser.new do |opt|
11
11
  opt.banner = "Usage: rails benchmarker 'Ruby.code' 'Ruby.more_code' ... [OPTS]"
12
12
  opt.on('-r', '--runs N', Numeric, 'Number of runs.', "Default: #{defaults[:runs]}") { |r| options[:runs] = r }
@@ -15,13 +15,13 @@ def options
15
15
  opt.on('-f', '--formats x,y,z', Array, 'Formats to output to.', "Default: #{defaults[:formats].join(",")}") { |m| options[:formats] = m.map(&:to_sym) }
16
16
  opt.parse!(ARGV)
17
17
  end
18
-
18
+
19
19
  options
20
20
  end
21
21
 
22
22
  class ProfilerTest < ActionDispatch::PerformanceTest
23
23
  self.profile_options = options
24
-
24
+
25
25
  ARGV.each do |expression|
26
26
  eval <<-RUBY
27
27
  def test_#{expression.parameterize('_')}
@@ -43,7 +43,7 @@ module Rails
43
43
  end
44
44
 
45
45
  def app
46
- @app ||= super.instance
46
+ @app ||= super.respond_to?(:to_app) ? super.to_app : super
47
47
  end
48
48
 
49
49
  def opt_parser
@@ -78,6 +78,7 @@ module Rails
78
78
  middlewares = []
79
79
  middlewares << [Rails::Rack::LogTailer, log_path] unless options[:daemonize]
80
80
  middlewares << [Rails::Rack::Debugger] if options[:debugger]
81
+ middlewares << [Rails::Rack::ContentLength]
81
82
  Hash.new(middlewares)
82
83
  end
83
84
 
@@ -43,6 +43,7 @@ module Rails
43
43
 
44
44
  class Generators #:nodoc:
45
45
  attr_accessor :aliases, :options, :templates, :fallbacks, :colorize_logging
46
+ attr_reader :hidden_namespaces
46
47
 
47
48
  def initialize
48
49
  @aliases = Hash.new { |h,k| h[k] = {} }
@@ -50,6 +51,7 @@ module Rails
50
51
  @fallbacks = {}
51
52
  @templates = []
52
53
  @colorize_logging = true
54
+ @hidden_namespaces = []
53
55
  end
54
56
 
55
57
  def initialize_copy(source)
@@ -59,6 +61,10 @@ module Rails
59
61
  @templates = @templates.dup
60
62
  end
61
63
 
64
+ def hide_namespace(namespace)
65
+ @hidden_namespaces << namespace
66
+ end
67
+
62
68
  def method_missing(method, *args)
63
69
  method = method.to_s.sub(/=$/, '').to_sym
64
70
 
@@ -387,7 +387,7 @@ module Rails
387
387
  delegate :middleware, :root, :paths, :to => :config
388
388
  delegate :engine_name, :isolated?, :to => "self.class"
389
389
 
390
- def load_tasks
390
+ def load_tasks(*)
391
391
  super
392
392
  paths["lib/tasks"].existent.sort.each { |ext| load(ext) }
393
393
  end
@@ -57,7 +57,7 @@ module Rails
57
57
  :resource_controller => :controller,
58
58
  :scaffold_controller => :scaffold_controller,
59
59
  :stylesheets => true,
60
- :stylesheet_engine => nil,
60
+ :stylesheet_engine => :css,
61
61
  :test_framework => false,
62
62
  :template_engine => :erb
63
63
  },
@@ -75,6 +75,7 @@ module Rails
75
75
  fallbacks.merge! config.fallbacks
76
76
  templates_path.concat config.templates
77
77
  templates_path.uniq!
78
+ hide_namespaces *config.hidden_namespaces
78
79
  end
79
80
 
80
81
  def self.templates_path
@@ -175,6 +176,7 @@ module Rails
175
176
  orm = options[:rails][:orm]
176
177
  test = options[:rails][:test_framework]
177
178
  template = options[:rails][:template_engine]
179
+ css = options[:rails][:stylesheet_engine]
178
180
 
179
181
  [
180
182
  "rails",
@@ -194,7 +196,11 @@ module Rails
194
196
  "#{test}:plugin",
195
197
  "#{template}:controller",
196
198
  "#{template}:scaffold",
197
- "#{template}:mailer"
199
+ "#{template}:mailer",
200
+ "#{css}:scaffold",
201
+ "#{css}:assets",
202
+ "css:assets",
203
+ "css:scaffold"
198
204
  ]
199
205
  end
200
206
  end
@@ -0,0 +1,13 @@
1
+ require "rails/generators/named_base"
2
+
3
+ module Css
4
+ module Generators
5
+ class AssetsGenerator < Rails::Generators::NamedBase
6
+ source_root File.expand_path("../templates", __FILE__)
7
+
8
+ def copy_stylesheet
9
+ copy_file "stylesheet.css", File.join('app/assets/stylesheets', class_path, "#{file_name}.css")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,4 @@
1
- /*
1
+ /*
2
2
  Place all the styles related to the matching controller here.
3
3
  They will automatically be included in application.css.
4
- You can use Sass (SCSS) here: http://sass-lang.com/
5
4
  */
@@ -0,0 +1,16 @@
1
+ require "rails/generators/named_base"
2
+
3
+ module Css
4
+ module Generators
5
+ class ScaffoldGenerator < Rails::Generators::NamedBase
6
+ # In order to allow the Sass generators to pick up the default Rails CSS and
7
+ # transform it, we leave it in a standard location for the CSS stylesheet
8
+ # generators to handle. For the simple, default case, just copy it over.
9
+ def copy_stylesheet
10
+ dir = Rails::Generators::ScaffoldGenerator.source_root
11
+ file = File.join(dir, "scaffold.css")
12
+ create_file "app/assets/stylesheets/scaffold.css", File.read(file)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -272,7 +272,7 @@ module Rails
272
272
  end
273
273
 
274
274
  def app_secret
275
- ActiveSupport::SecureRandom.hex(64)
275
+ SecureRandom.hex(64)
276
276
  end
277
277
 
278
278
  def mysql_socket
@@ -4,10 +4,10 @@ source 'http://rubygems.org'
4
4
 
5
5
  <%= database_gemfile_entry -%>
6
6
 
7
- <%= "gem 'jruby-openssl'\n" if defined?(JRUBY_VERSION) && JRUBY_VERSION < "1.6" -%>
7
+ <%= "gem 'jruby-openssl'\n" if defined?(JRUBY_VERSION) -%>
8
8
  # Asset template engines
9
9
  <%= "gem 'json'\n" if RUBY_VERSION < "1.9.2" -%>
10
- gem 'sass'
10
+ gem 'sass-rails', "~> 3.1.0.rc"
11
11
  gem 'coffee-script'
12
12
  gem 'uglifier'
13
13
 
@@ -39,17 +39,6 @@ module <%= app_const_base %>
39
39
  # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
40
40
  # config.i18n.default_locale = :de
41
41
 
42
- # Please note that JavaScript expansions are *ignored altogether* if the asset
43
- # pipeline is enabled (see config.assets.enabled below). Put your defaults in
44
- # app/assets/javascripts/application.js in that case.
45
- #
46
- # JavaScript files you want as :defaults (application.js is always included).
47
- <% if options[:skip_javascript] -%>
48
- # config.action_view.javascript_expansions[:defaults] = %w()
49
- <% else -%>
50
- # config.action_view.javascript_expansions[:defaults] = %w(prototype prototype_ujs)
51
- <% end -%>
52
-
53
42
  # Configure the default encoding used in templates for Ruby 1.9.
54
43
  config.encoding = "utf-8"
55
44
 
@@ -21,4 +21,7 @@
21
21
 
22
22
  # Only use best-standards-support built into browsers
23
23
  config.action_dispatch.best_standards_support = :builtin
24
+
25
+ # Do not compress assets
26
+ config.assets.compress = false
24
27
  end
@@ -11,9 +11,11 @@
11
11
  # Disable Rails's static asset server (Apache or nginx will already do this)
12
12
  config.serve_static_assets = false
13
13
 
14
- # Compress both stylesheets and JavaScripts
14
+ # Compress JavaScripts and CSS
15
+ config.assets.compress = true
16
+
17
+ # Specify the default JavaScript compressor
15
18
  config.assets.js_compressor = :uglifier
16
- config.assets.css_compressor = :scss
17
19
 
18
20
  # Specifies the header that your server uses for sending files
19
21
  # (comment out if your front-end server doesn't support this)
@@ -1,7 +1,7 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
  #
3
- # This file contains the settings for ActionController::ParametersWrapper
4
- # which will be enabled by default in the upcoming version of Ruby on Rails.
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
5
 
6
6
  # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
7
  ActionController::Base.wrap_parameters <%= key_value :format, "[:json]" %>
@@ -5,7 +5,7 @@ class BrowsingTest < ActionDispatch::PerformanceTest
5
5
  # Refer to the documentation for all available options
6
6
  # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
7
7
  # :output => 'tmp/performance', :formats => [:flat] }
8
-
8
+
9
9
  def test_homepage
10
10
  get '/'
11
11
  end