diff options
Diffstat (limited to 'guides/source')
-rw-r--r-- | guides/source/4_2_release_notes.md | 243 | ||||
-rw-r--r-- | guides/source/action_controller_overview.md | 55 | ||||
-rw-r--r-- | guides/source/action_mailer_basics.md | 2 | ||||
-rw-r--r-- | guides/source/active_record_migrations.md | 3 | ||||
-rw-r--r-- | guides/source/active_record_postgresql.md | 10 | ||||
-rw-r--r-- | guides/source/api_documentation_guidelines.md | 36 | ||||
-rw-r--r-- | guides/source/command_line.md | 25 | ||||
-rw-r--r-- | guides/source/configuring.md | 6 | ||||
-rw-r--r-- | guides/source/engines.md | 2 | ||||
-rw-r--r-- | guides/source/getting_started.md | 5 | ||||
-rw-r--r-- | guides/source/upgrading_ruby_on_rails.md | 8 |
11 files changed, 381 insertions, 14 deletions
diff --git a/guides/source/4_2_release_notes.md b/guides/source/4_2_release_notes.md new file mode 100644 index 0000000000..be007f93a7 --- /dev/null +++ b/guides/source/4_2_release_notes.md @@ -0,0 +1,243 @@ +Ruby on Rails 4.2 Release Notes +=============================== + +Highlights in Rails 4.2: + +These release notes cover only the major changes. To know about various bug +fixes and changes, please refer to the change logs or check out the +[list of commits](https://github.com/rails/rails/commits/master) in the main +Rails repository on GitHub. + +-------------------------------------------------------------------------------- + +Upgrading to Rails 4.2 +---------------------- + +If you're upgrading an existing application, it's a great idea to have good test +coverage before going in. You should also first upgrade to Rails 4.1 in case you +haven't and make sure your application still runs as expected before attempting +an update to Rails 4.2. A list of things to watch out for when upgrading is +available in the +[Upgrading Ruby on Rails](upgrading_ruby_on_rails.html#upgrading-from-rails-4-1-to-rails-4-2) +guide. + + +Major Features +-------------- + + + +Railties +-------- + +Please refer to the +[Changelog](https://github.com/rails/rails/blob/4-2-stable/railties/CHANGELOG.md) +for detailed changes. + +### Removals + +* The `rails application` command has been removed without replacement. + ([Pull Request](https://github.com/rails/rails/pull/11616)) + +### Notable changes + +* Introduced `bin/setup` script to bootstrap an application. + ([Pull Request](https://github.com/rails/rails/pull/15189)) + +* Changed default value for `config.assets.digest` to `true` in development. + ([Pull Request](https://github.com/rails/rails/pull/15155)) + +* Introduced an API to register new extensions for `rake notes`. + ([Pull Request](https://github.com/rails/rails/pull/14379)) + +* Introduced `Rails.gem_version` as a convenience method to return `Gem::Version.new(Rails.version)`. + ([Pull Request](https://github.com/rails/rails/pull/14101)) + + +Action Pack +----------- + +Please refer to the +[Changelog](https://github.com/rails/rails/blob/4-2-stable/actionpack/CHANGELOG.md) +for detailed changes. + +### Deprecations + +* Deprecated support for setting the `to:` option of a router to a symbol or a + string that does not contain a `#` character: + + get '/posts', to: MyRackApp => (No change necessary) + get '/posts', to: 'post#index' => (No change necessary) + get '/posts', to: 'posts' => get '/posts', controller: :posts + get '/posts', to: :index => get '/posts', action: :index + + ([Commit](https://github.com/rails/rails/commit/cc26b6b7bccf0eea2e2c1a9ebdcc9d30ca7390d9)) + +### Notable changes + +* The `*_filter` family methods has been removed from the documentation. Their + usage are discouraged in favor of the `*_action` family methods: + + after_filter => after_action + append_after_filter => append_after_action + append_around_filter => append_around_action + append_before_filter => append_before_action + around_filter => around_action + before_filter => before_action + prepend_after_filter => prepend_after_action + prepend_around_filter => prepend_around_action + prepend_before_filter => prepend_before_action + skip_after_filter => skip_after_action + skip_around_filter => skip_around_action + skip_before_filter => skip_before_action + skip_filter => skip_action_callback + + If your application is depending on these methods, you should use the + replacement `*_action` methods instead. These methods will be deprecated in + the future and eventually removed from Rails. + (Commit [1](https://github.com/rails/rails/commit/6c5f43bab8206747a8591435b2aa0ff7051ad3de), + [2](https://github.com/rails/rails/commit/489a8f2a44dc9cea09154ee1ee2557d1f037c7d4)) + +* Added HTTP method `MKCALENDAR` from RFC-4791 + ([Pull Request](https://github.com/rails/rails/pull/15121)) + +* `*_fragment.action_controller` notifications now include the controller and action name + in the payload. + ([Pull Request](https://github.com/rails/rails/pull/14137)) + +* Segments that are passed into URL helpers are now automatically escaped. + ([Commit](https://github.com/rails/rails/commit/5460591f0226a9d248b7b4f89186bd5553e7768f)) + +* Improved Routing Error page with fuzzy matching for route search. + ([Pull Request](https://github.com/rails/rails/pull/14619)) + +* Added option to disable logging of CSRF failures. + ([Pull Request](https://github.com/rails/rails/pull/14280)) + + +Action Mailer +------------- + +Please refer to the +[Changelog](https://github.com/rails/rails/blob/4-2-stable/actionmailer/CHANGELOG.md) +for detailed changes. + +### Notable changes + + +Active Record +------------- + +Please refer to the +[Changelog](https://github.com/rails/rails/blob/4-2-stable/activerecord/CHANGELOG.md) +for detailed changes. + +### Deprecations + +* Deprecated using `.joins`, `.preload` and `.eager_load` with associations that + depends on the instance state (i.e. those defined with a scope that takes an + argument) without replacement. + ([Commit](https://github.com/rails/rails/commit/ed56e596a0467390011bc9d56d462539776adac1)) + +* Deprecated passing Active Record objects to `.find` or `.exists?`. Call `#id` + on the objects first. + (Commit [1](https://github.com/rails/rails/commit/d92ae6ccca3bcfd73546d612efaea011270bd270), + [2](https://github.com/rails/rails/commit/d35f0033c7dec2b8d8b52058fb8db495d49596f7)) + +* Deprecated half-baked support for PostgreSQL range values with excluding + beginnings. We currently map PostgreSQL ranges to Ruby ranges. This conversion + is not fully possible because the Ruby range does not support excluded + beginnings. + + The current solution of incrementing the beginning is not correct and is now + deprecated. For subtypes where we don't know how to increment (e.g. `#succ` + is not defined) it will raise an `ArgumentError` for ranges with excluding + beginnings. + + ([Commit](https://github.com/rails/rails/commit/91949e48cf41af9f3e4ffba3e5eecf9b0a08bfc3)) + +### Notable changes + +* Added support for `#pretty_print` in `ActiveRecord::Base` objects. + ([Pull Request](https://github.com/rails/rails/pull/15172)) + +* PostgreSQL and SQLite adapters no longer add a default limit of 255 characters + on string columns. + ([Pull Request](https://github.com/rails/rails/pull/14579)) + +* `sqlite3:///some/path` now resolves to the absolute system path `/some/path`. + For relative paths, use `sqlite3:some/path` instead. (Previously, `sqlite3:///some/path` + resolved to the relative path `some/path`. This behaviour was deprecated on + Rails 4.1.) + ([Pull Request](https://github.com/rails/rails/pull/14569)) + +* Introduced `#validate` as an alias for `#valid?`. + ([Pull Request](https://github.com/rails/rails/pull/14456)) + +* `#touch` now accepts multiple attributes to be touched at once. + ([Pull Request](https://github.com/rails/rails/pull/14423)) + +* Added support for fractional seconds for MySQL 5.6 and above. + (Pull Request [1](https://github.com/rails/rails/pull/8240), [2](https://github.com/rails/rails/pull/14359)) + +* Added support for the `citext` column type in PostgreSQL adapter. + ([Pull Request](https://github.com/rails/rails/pull/12523)) + +* Added support for user-created range types in PostgreSQL adapter. + ([Commit](https://github.com/rails/rails/commit/4cb47167e747e8f9dc12b0ddaf82bdb68c03e032)) + +Active Model +------------ + +Please refer to the +[Changelog](https://github.com/rails/rails/blob/4-2-stable/activemodel/CHANGELOG.md) +for detailed changes. + +### Notable changes + +* Introduced `#validate` as an alias for `#valid?`. + ([Pull Request](https://github.com/rails/rails/pull/14456)) + + +Active Support +-------------- + +Please refer to the +[Changelog](https://github.com/rails/rails/blob/4-2-stable/activesupport/CHANGELOG.md) +for detailed changes. + +### Removals + +* Removed deprecated `Numeric#ago`, `Numeric#until`, `Numeric#since`, + `Numeric#from_now`. ([Commit](https://github.com/rails/rails/commit/f1eddea1e3f6faf93581c43651348f48b2b7d8bb)) + +* Removed deprecated string based terminators for `ActiveSupport::Callbacks`. + ([Pull Request](https://github.com/rails/rails/pull/15100)) + +### Deprecations + +* Deprecated `Class#superclass_delegating_accessor`, use `Class#class_attribute` + instead. ([Pull Request](https://github.com/rails/rails/pull/14271)) + +* Deprecated `ActiveSupport::SafeBuffer#prepend!` as `ActiveSupport::SafeBuffer#prepend` + now performs the same function. ([Pull Request](https://github.com/rails/rails/pull/14529)) + +### Notable changes + +* The `humanize` inflector helper now strips any leading underscores. + ([Commit](https://github.com/rails/rails/commit/daaa21bc7d20f2e4ff451637423a25ff2d5e75c7)) + +* Added `SecureRandom::uuid_v3` and `SecureRandom::uuid_v5`. + ([Pull Request](https://github.com/rails/rails/pull/12016)) + +* Introduce `Concern#class_methods` as an alternative to `module ClassMethods`, + as well as `Kernel#concern` to avoid the `module Foo; extend ActiveSupport::Concern; end` + boilerplate. ([Commit](https://github.com/rails/rails/commit/b16c36e688970df2f96f793a759365b248b582ad)) + +Credits +------- + +See the +[full list of contributors to Rails](http://contributors.rubyonrails.org/) for +the many people who spent many hours making Rails, the stable and robust +framework it is. Kudos to all of them. diff --git a/guides/source/action_controller_overview.md b/guides/source/action_controller_overview.md index 3d15319ca4..57097ab146 100644 --- a/guides/source/action_controller_overview.md +++ b/guides/source/action_controller_overview.md @@ -1166,6 +1166,61 @@ end NOTE: Certain exceptions are only rescuable from the `ApplicationController` class, as they are raised before the controller gets initialized and the action gets executed. See Pratik Naik's [article](http://m.onkey.org/2008/7/20/rescue-from-dispatching) on the subject for more information. + +### Custom errors page + +You can customize the layout of your error handling using controllers and views. +First define your app own routes to display the errors page. + +* `config/application.rb` + + ```ruby + config.exceptions_app = self.routes + ``` + +* `config/routes.rb` + + ```ruby + get '/404', to: 'errors#not_found' + get '/422', to: 'errors#unprocessable_entity' + get '/500', to: 'errors#server_error' + ``` + +Create the controller and views. + +* `app/controllers/errors_controller.rb` + + ```ruby + class ErrorsController < ActionController::Base + layout 'error' + + def not_found + render status: :not_found + end + + def unprocessable_entity + render status: :unprocessable_entity + end + + def server_error + render status: :server_error + end + end + ``` + +* `app/views` + + ``` + errors/ + not_found.html.erb + unprocessable_entity.html.erb + server_error.html.erb + layouts/ + error.html.erb + ``` + +Do not forget to set the correct status code on the controller as shown before. You should avoid using the database or any complex operations because the user is already on the error page. Generating another error while on an error page could cause issues. + Force HTTPS protocol -------------------- diff --git a/guides/source/action_mailer_basics.md b/guides/source/action_mailer_basics.md index c7117027c0..cb1c1c653d 100644 --- a/guides/source/action_mailer_basics.md +++ b/guides/source/action_mailer_basics.md @@ -309,7 +309,7 @@ email address in the format `"Full Name <email>"`. ```ruby def welcome_email(user) @user = user - email_with_name = "#{@user.name} <#{@user.email}>" + email_with_name = %("#{@user.name}" <#{@user.email}>) mail(to: email_with_name, subject: 'Welcome to My Awesome Site') end ``` diff --git a/guides/source/active_record_migrations.md b/guides/source/active_record_migrations.md index 5a550d9e55..fd2125424b 100644 --- a/guides/source/active_record_migrations.md +++ b/guides/source/active_record_migrations.md @@ -434,6 +434,9 @@ change_column_default :products, :approved, false This sets `:name` field on products to a `NOT NULL` column and the default value of the `:approved` field to false. +TIP: Unlike `change_column` (and `change_column_default`), `change_column_null` +is reversible. + ### Column Modifiers Column modifiers can be applied when creating or changing a column: diff --git a/guides/source/active_record_postgresql.md b/guides/source/active_record_postgresql.md index fa135b537c..a5649e3903 100644 --- a/guides/source/active_record_postgresql.md +++ b/guides/source/active_record_postgresql.md @@ -8,6 +8,7 @@ After reading this guide, you will know: * How to use PostgreSQL's datatypes. * How to use UUID primary keys. * How to implement full text search with PostgreSQL. +* How to back your Active Record models with database views. -------------------------------------------------------------------------------- @@ -324,7 +325,8 @@ macbook.address * [type definition](http://www.postgresql.org/docs/9.3/static/datatype-geometric.html) -All geometric types are mapped to normal text. +All geometric types, with the exception of `points` are mapped to normal text. +A point is casted to an array containing `x` and `y` coordinates. UUID Primary Keys @@ -372,8 +374,8 @@ Document.where("to_tsvector('english', title || ' ' || body) @@ to_tsquery(?)", "cat & dog") ``` -Views ------ +Database Views +-------------- * [view creation](http://www.postgresql.org/docs/9.3/static/sql-createview.html) @@ -428,7 +430,7 @@ second = Article.create! title: "Brace yourself", Article.count # => 1 first.archive! -p Article.count # => 2 +Article.count # => 2 ``` NOTE: This application only cares about non-archived `Articles`. A view also diff --git a/guides/source/api_documentation_guidelines.md b/guides/source/api_documentation_guidelines.md index dda9baa8d7..7e9b288ffd 100644 --- a/guides/source/api_documentation_guidelines.md +++ b/guides/source/api_documentation_guidelines.md @@ -13,7 +13,8 @@ After reading this guide, you will know: RDoc ---- -The [Rails API documentation](http://api.rubyonrails.org) is generated with RDoc. +The [Rails API documentation](http://api.rubyonrails.org) is generated with +[RDoc](http://docs.seattlerb.org/rdoc/). ```bash bundle exec rake rdoc @@ -21,6 +22,11 @@ The [Rails API documentation](http://api.rubyonrails.org) is generated with RDoc Resulting HTML files can be found in the ./doc/rdoc directory. +Please consult the RDoc documentation for help with the +[markup](http://docs.seattlerb.org/rdoc/RDoc/Markup.html), +and also take into account these [additional +directives](http://docs.seattlerb.org/rdoc/RDoc/Parser/Ruby.html). + Wording ------- @@ -324,4 +330,32 @@ A `:nodoc:` should never be added simply because a method or class is missing do To summarize, the Rails team uses `:nodoc:` to mark publicly visible methods and classes for internal use; changes to the visibility of API should be considered carefully and discussed over a pull request first. +Regarding the Rails Stack +------------------------- + +When documenting parts of Rails API, it's important to remember all of the +pieces that go into the Rails stack. + +This means that behavior may change depending on the scope or context of the +method or class you're trying to document. + +In various places there is different behavior when you take the entire stack +into account, one such example is +`ActionView::Helpers::AssetTagHelper#image_tag`: + +```ruby +# image_tag("icon.png") +# # => <img alt="Icon" src="/assets/icon.png" /> +``` + +Although the default behavior for `#image_tag` is to always return +`/images/icon.png`, we take into account the full Rails stack (including the +Asset Pipeline) we may see the result seen above. + +We're only concerned with the behavior experienced when using the full default +Rails stack. + +In this case, we want to document the behavior of the _framework_, and not just +this specific method. + If you have a question on how the Rails team handles certain API, don't hesitate to open a ticket or send a patch to the [issue tracker](https://github.com/rails/rails/issues). diff --git a/guides/source/command_line.md b/guides/source/command_line.md index 7e60f929a1..e283bcd0ef 100644 --- a/guides/source/command_line.md +++ b/guides/source/command_line.md @@ -294,6 +294,31 @@ Any modifications you make will be rolled back on exit irb(main):001:0> ``` +#### The app and helper objects + +Inside the `rails console` you have access to the `app` and `helper` instances. + +With the `app` method you can access url and path helpers, as well as do requests. + +```bash +>> app.root_path +=> "/" + +>> app.get _ +Started GET "/" for 127.0.0.1 at 2014-06-19 10:41:57 -0300 +... +``` + +With the `helper` method it is possible to access Rails and your application's helpers. + +```bash +>> helper.time_ago_in_words 30.days.ago +=> "about 1 month" + +>> helper.my_custom_helper +=> "my custom helper" +``` + ### `rails dbconsole` `rails dbconsole` figures out which database you're using and drops you into whichever command line interface you would use with it (and figures out the command line parameters to give to it, too!). It supports MySQL, PostgreSQL, SQLite and SQLite3. diff --git a/guides/source/configuring.md b/guides/source/configuring.md index a0f0738fba..3d6b2f79c6 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -552,7 +552,7 @@ development: $ echo $DATABASE_URL postgresql://localhost/my_database -$ bin/rails runner 'puts ActiveRecord::Base.connections' +$ bin/rails runner 'puts ActiveRecord::Base.configurations' {"development"=>{"adapter"=>"postgresql", "host"=>"localhost", "database"=>"my_database"}} ``` @@ -569,7 +569,7 @@ development: $ echo $DATABASE_URL postgresql://localhost/my_database -$ bin/rails runner 'puts ActiveRecord::Base.connections' +$ bin/rails runner 'puts ActiveRecord::Base.configurations' {"development"=>{"adapter"=>"postgresql", "host"=>"localhost", "database"=>"my_database", "pool"=>5}} ``` @@ -585,7 +585,7 @@ development: $ echo $DATABASE_URL postgresql://localhost/my_database -$ bin/rails runner 'puts ActiveRecord::Base.connections' +$ bin/rails runner 'puts ActiveRecord::Base.configurations' {"development"=>{"adapter"=>"sqlite3", "database"=>"NOT_my_database"}} ``` diff --git a/guides/source/engines.md b/guides/source/engines.md index e7f024f1fc..4041cd7d55 100644 --- a/guides/source/engines.md +++ b/guides/source/engines.md @@ -94,7 +94,7 @@ including a skeleton structure that provides the following: ``` * A file at `lib/blorgh/engine.rb`, which is identical in function to a - * standard Rails application's `config/application.rb` file: + standard Rails application's `config/application.rb` file: ```ruby module Blorgh diff --git a/guides/source/getting_started.md b/guides/source/getting_started.md index 3122a3dacb..ea6c8cdd55 100644 --- a/guides/source/getting_started.md +++ b/guides/source/getting_started.md @@ -70,11 +70,10 @@ Creating a New Rails Project The best way to use this guide is to follow each step as it happens, no code or step needed to make this example application has been left out, so you can -literally follow along step by step. You can get the complete code -[here](https://github.com/rails/docrails/tree/master/guides/code/getting_started). +literally follow along step by step. By following along with this guide, you'll create a Rails project called -`blog`, a (very) simple weblog. Before you can start building the application, +`blog`, a (very) simple weblog. Before you can start building the application, you need to make sure that you have Rails itself installed. TIP: The examples below use `$` to represent your terminal prompt in a UNIX-like OS, diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index 03d1f2a3a0..d7dbfccb76 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -22,6 +22,12 @@ Rails generally stays close to the latest released Ruby version when it's releas TIP: Ruby 1.8.7 p248 and p249 have marshaling bugs that crash Rails. Ruby Enterprise Edition has these fixed since the release of 1.8.7-2010.02. On the 1.9 front, Ruby 1.9.1 is not usable because it outright segfaults, so if you want to use 1.9.x, jump straight to 1.9.3 for smooth sailing. +Upgrading from Rails 4.1 to Rails 4.2 +------------------------------------- + +NOTE: This section is a work in progress. + + Upgrading from Rails 4.0 to Rails 4.1 ------------------------------------- @@ -140,7 +146,7 @@ If you use the cookie session store, this would apply to the `session` and Flash message keys are [normalized to strings](https://github.com/rails/rails/commit/a668beffd64106a1e1fedb71cc25eaaa11baf0c1). They -can still be accessed using either symbols or strings. Lopping through the flash +can still be accessed using either symbols or strings. Looping through the flash will always yield string keys: ```ruby |