diff options
Diffstat (limited to 'railties/guides')
17 files changed, 184 insertions, 97 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..d2cd5c028b 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 @@ -37,13 +37,19 @@ module Blog # Use SQL instead of Active Record's schema dumper when creating the database. # This is necessary if your schema can't be completely dumped by the schema dumper, - # like if you have constraints or database-specific column types + # like if you have constraints or database-specific column types. # config.active_record.schema_format = :sql - # Enable the asset pipeline + # 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 - # Version of your assets, change this if you want to expire all your assets + # Version of your assets, change this if you want to expire all your assets. config.assets.version = '1.0' end end diff --git a/railties/guides/code/getting_started/config/environments/development.rb b/railties/guides/code/getting_started/config/environments/development.rb index aefd25c6b6..cec2b20c0b 100644 --- a/railties/guides/code/getting_started/config/environments/development.rb +++ b/railties/guides/code/getting_started/config/environments/development.rb @@ -1,34 +1,34 @@ Blog::Application.configure do - # Settings specified here will take precedence over those in config/application.rb + # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. config.cache_classes = false - # Show full error reports and disable caching + # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false - # Don't care if the mailer can't send + # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false - # Print deprecation notices to the Rails logger + # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log - # Only use best-standards-support built into browsers + # Only use best-standards-support built into browsers. config.action_dispatch.best_standards_support = :builtin - # Raise exception on mass assignment protection for ActiveRecord models + # Raise exception on mass assignment protection for ActiveRecord models. config.active_record.mass_assignment_sanitizer = :strict # Log the query plan for queries taking more than this (works - # with SQLite, MySQL, and PostgreSQL) + # with SQLite, MySQL, and PostgreSQL). config.active_record.auto_explain_threshold_in_seconds = 0.5 - # Do not compress assets + # Do not compress assets. config.assets.compress = false - # Expands the lines which load the assets + # Expands the lines which load the assets. config.assets.debug = true end diff --git a/railties/guides/code/getting_started/config/environments/production.rb b/railties/guides/code/getting_started/config/environments/production.rb index c9b2f41c39..cfb8c960d6 100644 --- a/railties/guides/code/getting_started/config/environments/production.rb +++ b/railties/guides/code/getting_started/config/environments/production.rb @@ -1,67 +1,67 @@ Blog::Application.configure do - # Settings specified here will take precedence over those in config/application.rb + # Settings specified here will take precedence over those in config/application.rb. - # Code is not reloaded between requests + # Code is not reloaded between requests. config.cache_classes = true - # Full error reports are disabled and caching is turned on + # Full error reports are disabled and caching is turned on. config.consider_all_requests_local = false config.action_controller.perform_caching = true - # Disable Rails's static asset server (Apache or nginx will already do this) + # Disable Rails's static asset server (Apache or nginx will already do this). config.serve_static_assets = false - # Compress JavaScripts and CSS + # Compress JavaScripts and CSS. config.assets.compress = true - # Don't fallback to assets pipeline if a precompiled asset is missed + # Don't fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = false - # Generate digests for assets URLs + # Generate digests for assets URLs. config.assets.digest = true - # Defaults to Rails.root.join("public/assets") + # Defaults to Rails.root.join("public/assets"). # config.assets.manifest = YOUR_PATH - # Specifies the header that your server uses for sending files + # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true - # See everything in the log (default is :info) + # See everything in the log (default is :info). # config.log_level = :debug - # Prepend all log lines with the following tags + # Prepend all log lines with the following tags. # config.log_tags = [ :subdomain, :uuid ] - # Use a different logger for distributed setups + # Use a different logger for distributed setups. # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) - # Use a different cache store in production + # Use a different cache store in production. # config.cache_store = :mem_cache_store - # Enable serving of images, stylesheets, and JavaScripts from an asset server + # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = "http://assets.example.com" - # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) + # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added). # config.assets.precompile += %w( search.js ) - # Disable delivery errors, bad email addresses will be ignored + # Disable delivery errors, bad email addresses will be ignored. # config.action_mailer.raise_delivery_errors = false - # Enable threaded mode + # Enable threaded mode. # config.threadsafe! # Enable locale fallbacks for I18n (makes lookups for any locale fall back to - # the I18n.default_locale when a translation can not be found) + # the I18n.default_locale when a translation can not be found). config.i18n.fallbacks = true - # Send deprecation notices to registered listeners + # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify # Log the query plan for queries taking more than this (works - # with SQLite, MySQL, and PostgreSQL) + # with SQLite, MySQL, and PostgreSQL). # config.active_record.auto_explain_threshold_in_seconds = 0.5 end diff --git a/railties/guides/code/getting_started/config/environments/test.rb b/railties/guides/code/getting_started/config/environments/test.rb index 1d45541d5c..f2bc932fb3 100644 --- a/railties/guides/code/getting_started/config/environments/test.rb +++ b/railties/guides/code/getting_started/config/environments/test.rb @@ -1,5 +1,5 @@ Blog::Application.configure do - # Settings specified here will take precedence over those in config/application.rb + # Settings specified here will take precedence over those in config/application.rb. # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that @@ -7,28 +7,28 @@ Blog::Application.configure do # and recreated between test runs. Don't rely on the data there! config.cache_classes = true - # Configure static asset server for tests with Cache-Control for performance + # Configure static asset server for tests with Cache-Control for performance. config.serve_static_assets = true config.static_cache_control = "public, max-age=3600" - # Show full error reports and disable caching + # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false - # Raise exceptions instead of rendering exception templates + # Raise exceptions instead of rendering exception templates. config.action_dispatch.show_exceptions = false - # Disable request forgery protection in test environment - config.action_controller.allow_forgery_protection = false + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test - # Print deprecation notices to the stderr - config.active_support.deprecation = :stderr + # Raise exception on mass assignment protection for Active Record models. + config.active_record.mass_assignment_sanitizer = :strict - # Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets - config.assets.allow_debugging = true + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr 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..d669a7fdfa 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,17 +285,19 @@ 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+. h3. Active Record -* Boolean columns with 'on' and 'ON' values are type casted to true. +* Boolean columns with 'on' and 'ON' values are type cast 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>. @@ -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..84687e2e4f 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. @@ -954,7 +965,7 @@ If you're working with dates or times within scopes, due to how they are evaluat <ruby> class Post < ActiveRecord::Base - scope :last_week, lambda { where("created_at < ?", Time.zone.now ) } + scope :created_before_now, lambda { where("created_at < ?", Time.zone.now ) } end </ruby> @@ -966,21 +977,21 @@ When a +lambda+ is used for a +scope+, it can take arguments: <ruby> class Post < ActiveRecord::Base - scope :1_week_before, lambda { |time| where("created_at < ?", time) } + scope :created_before, lambda { |time| where("created_at < ?", time) } end </ruby> This may then be called using this: <ruby> -Post.1_week_before(Time.zone.now) +Post.created_before(Time.zone.now) </ruby> However, this is just duplicating the functionality that would be provided to you by a class method. <ruby> class Post < ActiveRecord::Base - def self.1_week_before(time) + def self.created_before(time) where("created_at < ?", time) end end @@ -989,7 +1000,7 @@ end Using a class method is the preferred way to accept arguments for scopes. These methods will still be accessible on the association objects: <ruby> -category.posts.1_week_before(time) +category.posts.created_before(time) </ruby> h4. Working with scopes diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index a27c292a4c..15d24f9ac1 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -614,7 +614,7 @@ As shown in the example, you can also combine standard validations with your own h4. Custom Methods -You can also create methods that verify the state of your models and add messages to the +errors+ collection when they are invalid. You must then register these methods by using one or more of the +validate+, +validate_on_create+ or +validate_on_update+ class methods, passing in the symbols for the validation methods' names. +You can also create methods that verify the state of your models and add messages to the +errors+ collection when they are invalid. You must then register these methods by using the +validate+ class method, passing in the symbols for the validation methods' names. You can pass more than one symbol for each class method and the respective validations will be run in the same order as they were registered. @@ -637,12 +637,24 @@ class Invoice < ActiveRecord::Base end </ruby> +By default such validations will run every time you call +valid?+. It is also possible to control when to run these custom validations by giving an +:on+ option to the +validate+ method, with either: +:create+ or +:update+. + +<ruby> +class Invoice < ActiveRecord::Base + validate :active_customer, :on => :create + + def active_customer + errors.add(:customer_id, "is not active") unless customer.active? + end +end +</ruby> + You can even create your own validation helpers and reuse them in several different models. For example, an application that manages surveys may find it useful to express that a certain field corresponds to a set of choices: <ruby> ActiveRecord::Base.class_eval do def self.validates_as_choice(attr_name, n, options={}) - validates attr_name, :inclusion => { {:in => 1..n}.merge(options) } + validates attr_name, :inclusion => { { :in => 1..n }.merge!(options) } end end </ruby> @@ -659,7 +671,7 @@ h3. Working with Validation Errors In addition to the +valid?+ and +invalid?+ methods covered earlier, Rails provides a number of methods for working with the +errors+ collection and inquiring about the validity of objects. -The following is a list of the most commonly used methods. Please refer to the +ActiveRecord::Errors+ documentation for a list of all the available methods. +The following is a list of the most commonly used methods. Please refer to the +ActiveModel::Errors+ documentation for a list of all the available methods. h4(#working_with_validation_errors-errors). +errors+ @@ -889,13 +901,8 @@ Below is a simple example where we change the Rails behavior to always display t <ruby> ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| - if instance.error_message.kind_of?(Array) - %(#{html_tag}<span class="validation-error"> - #{instance.error_message.join(',')}</span>).html_safe - else - %(#{html_tag}<span class="validation-error"> - #{instance.error_message}</span>).html_safe - end + errors = Array(instance.error_message).join(',') + %(#{html_tag}<span class="validation-error"> #{errors}</span>).html_safe end </ruby> @@ -949,6 +956,7 @@ h4. Creating an Object * +before_validation+ * +after_validation+ * +before_save+ +* +around_save+ * +before_create+ * +around_create+ * +after_create+ @@ -959,6 +967,7 @@ h4. Updating an Object * +before_validation+ * +after_validation+ * +before_save+ +* +around_save+ * +before_update+ * +around_update+ * +after_update+ @@ -967,8 +976,8 @@ h4. Updating an Object h4. Destroying an Object * +before_destroy+ -* +after_destroy+ * +around_destroy+ +* +after_destroy+ WARNING. +after_save+ runs both on create and update, but always _after_ the more specific callbacks +after_create+ and +after_update+, no matter the order in which the macro calls were executed. @@ -1013,7 +1022,7 @@ The following methods trigger callbacks: * +increment!+ * +save+ * +save!+ -* +save(false)+ +* +save(:validate => false)+ * +toggle!+ * +update+ * +update_attribute+ diff --git a/railties/guides/source/active_resource_basics.textile b/railties/guides/source/active_resource_basics.textile index 851aac1a3f..37abb8a640 100644 --- a/railties/guides/source/active_resource_basics.textile +++ b/railties/guides/source/active_resource_basics.textile @@ -71,7 +71,7 @@ person.destroy h3. Validations -Module to support validation and errors with Active Resource objects. The module overrides Base#save to rescue ActiveResource::ResourceInvalid exceptions and parse the errors returned in the web service response. The module also adds an errors collection that mimics the interface of the errors provided by ActiveRecord::Errors. +Module to support validation and errors with Active Resource objects. The module overrides Base#save to rescue ActiveResource::ResourceInvalid exceptions and parse the errors returned in the web service response. The module also adds an errors collection that mimics the interface of the errors provided by ActiveModel::Errors. h4. Validating client side resources by overriding validation methods in base class diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index c77bc93cfb..bed14ef6a8 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -853,7 +853,7 @@ below: </erb> Now when you refresh the +/posts+ page, you'll see a gray background to the -page. This same gray background will be used throughout all the views for posts. +page. This same gray background will be used throughout all the views. h4. Creating New Posts @@ -1668,7 +1668,7 @@ right in the form where you create the post. First, create a new model to hold the tags: <shell> -$ rails generate model tag name:string post:references +$ rails generate model Tag name:string post:references </shell> Again, run the migration to create the database table: diff --git a/railties/guides/source/i18n.textile b/railties/guides/source/i18n.textile index 16ad35f345..25201888e7 100644 --- a/railties/guides/source/i18n.textile +++ b/railties/guides/source/i18n.textile @@ -819,13 +819,13 @@ h5. Action View Helper Methods * The +number_to_currency+, +number_with_precision+, +number_to_percentage+, +number_with_delimiter+, and +number_to_human_size+ helpers use the number format settings located in the "number":https://github.com/rails/rails/blob/master/actionpack/lib/action_view/locale/en.yml#L2 scope. -h5. Active Record Methods +h5. Active Model Methods * +model_name.human+ and +human_attribute_name+ use translations for model names and attribute names if available in the "activerecord.models":https://github.com/rails/rails/blob/master/activerecord/lib/active_record/locale/en.yml#L29 scope. They also support translations for inherited class names (e.g. for use with STI) as explained above in "Error message scopes". -* +ActiveRecord::Errors#generate_message+ (which is used by Active Record validations but may also be used manually) uses +model_name.human+ and +human_attribute_name+ (see above). It also translates the error message and supports translations for inherited class names as explained above in "Error message scopes". +* +ActiveModel::Errors#generate_message+ (which is used by Active Model validations but may also be used manually) uses +model_name.human+ and +human_attribute_name+ (see above). It also translates the error message and supports translations for inherited class names as explained above in "Error message scopes". -* +ActiveRecord::Errors#full_messages+ prepends the attribute name to the error message using a separator that will be looked up from "activerecord.errors.format.separator":https://github.com/rails/rails/blob/master/actionpack/lib/action_view/locale/en.yml#L91 (and which defaults to +' '+). +* +ActiveModel::Errors#full_messages+ prepends the attribute name to the error message using a separator that will be looked up from "errors.format":https://github.com/rails/rails/blob/master/activemodel/lib/active_model/locale/en.yml#L4 (and which defaults to +"%{attribute} %{message}"+). h5. Active Support Methods |