diff options
Diffstat (limited to 'railties')
14 files changed, 122 insertions, 64 deletions
diff --git a/railties/guides/code/getting_started/Gemfile b/railties/guides/code/getting_started/Gemfile index 898510dcaa..768985070c 100644 --- a/railties/guides/code/getting_started/Gemfile +++ b/railties/guides/code/getting_started/Gemfile @@ -1,8 +1,9 @@ -source 'http://rubygems.org' +source 'https://rubygems.org' + +gem 'rails', '3.2.0' -gem 'rails', '3.1.0' # Bundle edge Rails instead: -# gem 'rails', :git => 'git://github.com/rails/rails.git' +# gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'sqlite3' @@ -10,13 +11,23 @@ gem 'sqlite3' # Gems used only for assets and not required # in production environments by default. group :assets do - gem 'sass-rails', " ~> 3.1.0" - gem 'coffee-rails', "~> 3.1.0" - gem 'uglifier' + gem 'sass-rails', '~> 3.2.3' + gem 'coffee-rails', '~> 3.2.1' + + # See https://github.com/sstephenson/execjs#readme for more supported runtimes + # gem 'therubyracer' + + gem 'uglifier', '>= 1.0.3' end gem 'jquery-rails' +# To use ActiveModel has_secure_password +# gem 'bcrypt-ruby', '~> 3.0.0' + +# To use Jbuilder templates for JSON +# gem 'jbuilder' + # Use unicorn as the web server # gem 'unicorn' diff --git a/railties/guides/code/getting_started/app/assets/javascripts/application.js b/railties/guides/code/getting_started/app/assets/javascripts/application.js index 37c7bfcdb5..9097d830e2 100644 --- a/railties/guides/code/getting_started/app/assets/javascripts/application.js +++ b/railties/guides/code/getting_started/app/assets/javascripts/application.js @@ -1,9 +1,15 @@ -// This is a manifest file that'll be compiled into including all the files listed below. -// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically -// be included in the compiled file accessible from http://example.com/assets/application.js +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. +// // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // the compiled file. // +// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD +// GO AFTER THE REQUIRES BELOW. +// //= require jquery //= require jquery_ujs //= require_tree . diff --git a/railties/guides/code/getting_started/app/assets/stylesheets/application.css b/railties/guides/code/getting_started/app/assets/stylesheets/application.css index fc25b5723f..3b5cc6648e 100644 --- a/railties/guides/code/getting_started/app/assets/stylesheets/application.css +++ b/railties/guides/code/getting_started/app/assets/stylesheets/application.css @@ -1,7 +1,13 @@ /* - * This is a manifest file that'll automatically include all the stylesheets available in this directory - * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at - * the top of the compiled file, but it's generally better to create a new file per style scope. + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, + * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the top of the + * compiled file, but it's generally better to create a new file per style scope. + * *= require_self - *= require_tree . -*/
\ No newline at end of file + *= require_tree . +*/ diff --git a/railties/guides/code/getting_started/app/views/layouts/application.html.erb b/railties/guides/code/getting_started/app/views/layouts/application.html.erb index 7fd6b4f516..6578a41da2 100644 --- a/railties/guides/code/getting_started/app/views/layouts/application.html.erb +++ b/railties/guides/code/getting_started/app/views/layouts/application.html.erb @@ -6,7 +6,7 @@ <%= javascript_include_tag "application" %> <%= csrf_meta_tags %> </head> -<body style="background: #EEEEEE;"> +<body> <%= yield %> diff --git a/railties/guides/code/getting_started/config/application.rb b/railties/guides/code/getting_started/config/application.rb index 5f9010fced..dad91d7943 100644 --- a/railties/guides/code/getting_started/config/application.rb +++ b/railties/guides/code/getting_started/config/application.rb @@ -4,7 +4,7 @@ require 'rails/all' if defined?(Bundler) # If you precompile assets before deploying to production, use this line - Bundler.require *Rails.groups(:assets => %w(development test)) + Bundler.require(*Rails.groups(:assets => %w(development test))) # If you want your assets lazily compiled in production, use this line # Bundler.require(:default, :assets, Rails.env) end @@ -40,6 +40,12 @@ module Blog # like if you have constraints or database-specific column types # config.active_record.schema_format = :sql + # Enforce whitelist mode for mass assignment. + # This will create an empty whitelist of attributes available for mass-assignment for all models + # in your app. As such, your models will need to explicitly whitelist or blacklist accessible + # parameters by using an attr_accessible or attr_protected declaration. + # config.active_record.whitelist_attributes = true + # Enable the asset pipeline config.assets.enabled = true diff --git a/railties/guides/code/getting_started/config/environments/test.rb b/railties/guides/code/getting_started/config/environments/test.rb index 1d45541d5c..e97f82c6bd 100644 --- a/railties/guides/code/getting_started/config/environments/test.rb +++ b/railties/guides/code/getting_started/config/environments/test.rb @@ -26,9 +26,9 @@ Blog::Application.configure do # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test + # Raise exception on mass assignment protection for Active Record models + config.active_record.mass_assignment_sanitizer = :strict + # Print deprecation notices to the stderr config.active_support.deprecation = :stderr - - # Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets - config.assets.allow_debugging = true end diff --git a/railties/guides/code/getting_started/config/initializers/inflections.rb b/railties/guides/code/getting_started/config/initializers/inflections.rb index 9e8b0131f8..5d8d9be237 100644 --- a/railties/guides/code/getting_started/config/initializers/inflections.rb +++ b/railties/guides/code/getting_started/config/initializers/inflections.rb @@ -8,3 +8,8 @@ # inflect.irregular 'person', 'people' # inflect.uncountable %w( fish sheep ) # end +# +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/railties/guides/code/getting_started/config/routes.rb b/railties/guides/code/getting_started/config/routes.rb index 31f0d210db..b048ac68f1 100644 --- a/railties/guides/code/getting_started/config/routes.rb +++ b/railties/guides/code/getting_started/config/routes.rb @@ -1,7 +1,7 @@ Blog::Application.routes.draw do - resources :posts do - resources :comments - end + resources :posts do + resources :comments + end get "home/index" @@ -60,5 +60,5 @@ Blog::Application.routes.draw do # This is a legacy wild controller route that's not recommended for RESTful applications. # Note: This route will make all actions in every controller accessible via GET requests. - # match ':controller(/:action(/:id(.:format)))' + # match ':controller(/:action(/:id))(.:format)' end diff --git a/railties/guides/code/getting_started/public/500.html b/railties/guides/code/getting_started/public/500.html index b80307fc16..f3648a0dbc 100644 --- a/railties/guides/code/getting_started/public/500.html +++ b/railties/guides/code/getting_started/public/500.html @@ -20,7 +20,6 @@ <!-- This file lives in public/500.html --> <div class="dialog"> <h1>We're sorry, but something went wrong.</h1> - <p>We've been notified about this issue and we'll take a look at it shortly.</p> </div> </body> </html> diff --git a/railties/guides/source/3_2_release_notes.textile b/railties/guides/source/3_2_release_notes.textile index 439cd5f714..74bc757948 100644 --- a/railties/guides/source/3_2_release_notes.textile +++ b/railties/guides/source/3_2_release_notes.textile @@ -27,6 +27,7 @@ h4. What to update in your apps ** <tt>rails = 3.2.0</tt> ** <tt>sass-rails ~> 3.2.3</tt> ** <tt>coffee-rails ~> 3.2.1</tt> +** <tt>uglifier >= 1.0.3</tt> * Rails 3.2 deprecates <tt>vendor/plugins</tt> and Rails 4.0 will remove them completely. You can start replacing these plugins by extracting them as gems and adding them in your Gemfile. If you choose not to make them gems, you can move them into, say, <tt>lib/my_plugin/*</tt> and add an appropriate initializer in <tt>config/initializers/my_plugin.rb</tt>. @@ -138,10 +139,16 @@ will create indexes for +title+ and +author+ with the latter being an unique ind * Remove old <tt>config.paths.app.controller</tt> API in favor of <tt>config.paths["app/controller"]</tt>. -h4. Deprecations +h4(#railties_deprecations). Deprecations * +Rails::Plugin+ is deprecated and will be removed in Rails 4.0. Instead of adding plugins to +vendor/plugins+ use gems or bundler with path or git dependencies. +h3. Action Mailer + +* Upgraded <tt>mail</tt> version to 2.4.0. + +* Removed the old Action Mailer API which was deprecated since Rails 3.0. + h3. Action Pack h4. Action Controller @@ -198,7 +205,7 @@ We now no longer write out HTTP_COOKIE and the cookie jar is persistent between * Assets should use the request protocol by default or default to relative if no request is available. -h5. Deprecations +h5(#actioncontroller_deprecations). Deprecations * Deprecated implied layout lookup in controllers whose parent had a explicit layout set: @@ -219,8 +226,6 @@ In the example above, Posts controller will no longer automatically look up for * Deprecated <tt>method_missing</tt> in favour of +action_missing+ for missing actions. -* Deprecated <tt>ActionController#performed?</tt> in favour of checking for the presence of <tt>response_body</tt>. - * Deprecated <tt>ActionController#rescue_action</tt>, <tt>ActionController#initialize_template_class</tt> and <tt>ActionController#assign_shortcuts</tt>. h4. Action Dispatch @@ -233,7 +238,7 @@ h4. Action Dispatch * Allow rescue responses to be configured through a railtie as in <tt>config.action_dispatch.rescue_responses</tt>. -h5. Deprecations +h5(#actiondispatch_deprecations). Deprecations * Deprecated the ability to set a default charset at the controller level, use the new <tt>config.action_dispatch.default_charset</tt> instead. @@ -280,11 +285,11 @@ end * Added +font_path+ helper method that computes the path to a font asset in <tt>public/fonts</tt>. -h5. Deprecations +h5(#actionview_deprecations). Deprecations * Passing formats or handlers to render :template and friends like <tt>render :template => "foo.html.erb"</tt> is deprecated. Instead, you can provide :handlers and :formats directly as an options: <tt> render :template => "foo", :formats => [:html, :js], :handlers => :erb</tt>. -h3. Sprockets +h4. Sprockets * Adds a configuration option <tt>config.assets.logger</tt> to control Sprockets logging. Set it to +false+ to turn off logging and to +nil+ to default to +Rails.logger+. @@ -292,6 +297,8 @@ h3. Active Record * Boolean columns with 'on' and 'ON' values are type casted to true. +* When the +timestamps+ method creates the +created_at+ and +updated_at+ columns, it makes them non-nullable by default. + * Implemented <tt>ActiveRecord::Relation#explain</tt>. * Implements <tt>AR::Base.silence_auto_explain</tt> which allows the user to selectively disable automatic EXPLAINs within a block. @@ -365,7 +372,34 @@ has_many :clients, :class_name => :Client # Note that the symbol need to be capi User.where(:first_name => "Scarlett").first_or_create!(:last_name => "Johansson") </ruby> -h4. Deprecations +* Added a <tt>with_lock</tt> method to Active Record objects, which starts a transaction, locks the object (pessimistically) and yields to the block. The method takes one (optional) parameter and passes it to +lock!+. + +This makes it possible to write the following: + +<ruby> +class Order < ActiveRecord::Base + def cancel! + transaction do + lock! + # ... cancelling logic + end + end +end +</ruby> + +as: + +<ruby> +class Order < ActiveRecord::Base + def cancel! + with_lock do + # ... cancelling logic + end + end +end +</ruby> + +h4(#activerecord_deprecations). Deprecations * Automatic closure of connections in threads is deprecated. For example the following code is deprecated: @@ -413,7 +447,7 @@ h3. Active Model * Provide mass_assignment_sanitizer as an easy API to replace the sanitizer behavior. Also support both :logger (default) and :strict sanitizer behavior. -h4. Deprecations +h4(#activemodel_deprecations). Deprecations * Deprecated <tt>define_attr_method</tt> in <tt>ActiveModel::AttributeMethods</tt> because this only existed to support methods like +set_table_name+ in Active Record, which are themselves being deprecated. @@ -473,7 +507,7 @@ Event.where(:created_at => Time.now.all_day) * Removed <tt>ActiveSupport::SecureRandom</tt> in favor of <tt>SecureRandom</tt> from the standard library. -h4. Deprecations +h4(#activesupport_deprecations). Deprecations * +ActiveSupport::Base64+ is deprecated in favor of <tt>::Base64</tt>. diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index beada85ce3..5970a45839 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -692,6 +692,17 @@ Item.transaction do end </ruby> +If you already have an instance of your model, you can start a transaction and acquire the lock in one go using the following code: + +<ruby> +item = Item.first +item.with_lock do + # This block is called within a transaction, + # item is already locked. + item.increment!(:views) +end +</ruby> + h3. Joining Tables Active Record provides a finder method called +joins+ for specifying +JOIN+ clauses on the resulting SQL. There are multiple ways to use the +joins+ method. diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb index 20484a10c8..ea774eb16c 100644 --- a/railties/lib/rails/commands/server.rb +++ b/railties/lib/rails/commands/server.rb @@ -89,6 +89,7 @@ module Rails def default_options super.merge({ :Port => 3000, + :DoNotReverseLookup => true, :environment => (ENV['RAILS_ENV'] || "development").dup, :daemonize => false, :debugger => false, diff --git a/railties/lib/rails/deprecation.rb b/railties/lib/rails/deprecation.rb index 71adcd61f4..c5811b2629 100644 --- a/railties/lib/rails/deprecation.rb +++ b/railties/lib/rails/deprecation.rb @@ -1,39 +1,18 @@ -require "active_support/string_inquirer" -require "active_support/basic_object" +require 'active_support/deprecation/proxy_wrappers' module Rails - module Initializer - def self.run(&block) - klass = Class.new(Rails::Application) - klass.instance_exec(klass.config, &block) - klass.initialize! - end - end - - class DeprecatedConstant < ActiveSupport::BasicObject - def self.deprecate(old, new) - constant = self.new(old, new) + class DeprecatedConstant < ActiveSupport::Deprecation::DeprecatedConstantProxy + def self.deprecate(old, current) + constant = new(old, current) eval "::#{old} = constant" end - def initialize(old, new) - @old, @new = old, new - @target = ::Kernel.eval "proc { #{@new} }" - @warned = false - end - - def method_missing(meth, *args, &block) - ::ActiveSupport::Deprecation.warn("#{@old} is deprecated. Please use #{@new}") unless @warned - @warned = true + private - target = @target.call - if target.respond_to?(meth) - target.send(meth, *args, &block) - else - super - end + def target + ::Kernel.eval @new_const.to_s end end - DeprecatedConstant.deprecate("RAILS_CACHE", "::Rails.cache") + DeprecatedConstant.deprecate('RAILS_CACHE', '::Rails.cache') end diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 20321a502d..77a68eb7f1 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -228,7 +228,7 @@ module Rails # resources :articles # end # - # The routes above will automatically point to <tt>MyEngine::ApplicationController</tt>. Furthermore, you don't + # The routes above will automatically point to <tt>MyEngine::ArticlesController</tt>. Furthermore, you don't # need to use longer url helpers like <tt>my_engine_articles_path</tt>. Instead, you should simply use # <tt>articles_path</tt> as you would do with your application. # |