mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge branch 'master' of github.com:rails/docrails
This commit is contained in:
commit
216ec8d559
10 changed files with 83 additions and 37 deletions
|
@ -24,6 +24,9 @@ module ActiveRecord
|
|||
# serialized object must be of that class on retrieval or
|
||||
# <tt>SerializationTypeMismatch</tt> will be raised.
|
||||
#
|
||||
# A notable side effect of serialized attributes is that the model will
|
||||
# be updated on every save, even if it is not dirty.
|
||||
#
|
||||
# ==== Parameters
|
||||
#
|
||||
# * +attr_name+ - The field name that should be serialized.
|
||||
|
|
|
@ -15,6 +15,10 @@ module ActiveRecord
|
|||
# You can set custom coder to encode/decode your serialized attributes to/from different formats.
|
||||
# JSON, YAML, Marshal are supported out of the box. Generally it can be any wrapper that provides +load+ and +dump+.
|
||||
#
|
||||
# NOTE - If you are using special PostgreSQL columns like +hstore+ or +json+ there is no need for
|
||||
# the serialization provieded by +store+. You can simply use +store_accessor+ instead to generate
|
||||
# the accessor methods.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# class User < ActiveRecord::Base
|
||||
|
|
|
@ -604,7 +604,7 @@ Deprecated
|
|||
A few pieces of older code are deprecated in this release:
|
||||
|
||||
* If you're one of the (fairly rare) Rails developers who deploys in a fashion that depends on the inspector, reaper, and spawner scripts, you'll need to know that those scripts are no longer included in core Rails. If you need them, you'll be able to pick up copies via the [irs_process_scripts](http://github.com/rails/irs_process_scripts/tree) plugin.
|
||||
* `render_component` goes from "deprecated" to "nonexistent" in Rails 2.3. If you still need it, you can install the [render_component plugin](http://github.com/rails/render_component/tree/master.)
|
||||
* `render_component` goes from "deprecated" to "nonexistent" in Rails 2.3. If you still need it, you can install the [render_component plugin](http://github.com/rails/render_component/tree/master).
|
||||
* Support for Rails components has been removed.
|
||||
* If you were one of the people who got used to running `script/performance/request` to look at performance based on integration tests, you need to learn a new trick: that script has been removed from core Rails now. There's a new request_profiler plugin that you can install to get the exact same functionality back.
|
||||
* `ActionController::Base#session_enabled?` is deprecated because sessions are lazy-loaded now.
|
||||
|
|
|
@ -375,7 +375,7 @@ Active Record
|
|||
|
||||
* Support index sort order in SQLite, MySQL and PostgreSQL adapters.
|
||||
|
||||
* Allow the `:class_name` option for associations to take a symbol in addition to a string. This is to avoid confusing newbies, and to be consistent with the fact that other options like :foreign_key already allow a symbol or a string.
|
||||
* Allow the `:class_name` option for associations to take a symbol in addition to a string. This is to avoid confusing newbies, and to be consistent with the fact that other options like `:foreign_key` already allow a symbol or a string.
|
||||
|
||||
```ruby
|
||||
has_many :clients, :class_name => :Client # Note that the symbol need to be capitalized
|
||||
|
|
|
@ -165,9 +165,9 @@ Please refer to the [Changelog](https://github.com/rails/rails/blob/4-0-stable/a
|
|||
|
||||
### Notable changes
|
||||
|
||||
* Replace deprecated `memcache-client` gem with `dalli` in ActiveSupport::Cache::MemCacheStore.
|
||||
* Replace deprecated `memcache-client` gem with `dalli` in `ActiveSupport::Cache::MemCacheStore`.
|
||||
|
||||
* Optimize ActiveSupport::Cache::Entry to reduce memory and processing overhead.
|
||||
* Optimize `ActiveSupport::Cache::Entry` to reduce memory and processing overhead.
|
||||
|
||||
* Inflections can now be defined per locale. `singularize` and `pluralize` accept locale as an extra argument.
|
||||
|
||||
|
|
|
@ -290,7 +290,7 @@ Here's an example where we create a class with an `after_destroy` callback for a
|
|||
```ruby
|
||||
class PictureFileCallbacks
|
||||
def after_destroy(picture_file)
|
||||
if File.exists?(picture_file.filepath)
|
||||
if File.exist?(picture_file.filepath)
|
||||
File.delete(picture_file.filepath)
|
||||
end
|
||||
end
|
||||
|
@ -310,7 +310,7 @@ Note that we needed to instantiate a new `PictureFileCallbacks` object, since we
|
|||
```ruby
|
||||
class PictureFileCallbacks
|
||||
def self.after_destroy(picture_file)
|
||||
if File.exists?(picture_file.filepath)
|
||||
if File.exist?(picture_file.filepath)
|
||||
File.delete(picture_file.filepath)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -875,7 +875,7 @@ end
|
|||
|
||||
When Rails looks for a view to render, it will first look in the `app/views` directory of the application. If it cannot find the view there, then it will check in the `app/views` directories of all engines which have this directory.
|
||||
|
||||
In the `blorgh` engine, there is a currently a file at `app/views/blorgh/posts/index.html.erb`. When the engine is asked to render the view for `Blorgh::PostsController`'s `index` action, it will first see if it can find it at `app/views/blorgh/posts/index.html.erb` within the application and then if it cannot it will look inside the engine.
|
||||
When the application is asked to render the view for `Blorgh::PostsController`'s index action, it will look the path `app/views/blorgh/posts/index.html.erb`, first within the application. If it cannot find it, it will look inside the engine.
|
||||
|
||||
You can override this view in the application by simply creating a new file at `app/views/blorgh/posts/index.html.erb`. Then you can completely change what this view would normally output.
|
||||
|
||||
|
|
|
@ -492,12 +492,14 @@ Overview of the I18n API Features
|
|||
|
||||
You should have good understanding of using the i18n library now, knowing all necessary aspects of internationalizing a basic Rails application. In the following chapters, we'll cover it's features in more depth.
|
||||
|
||||
These chapters will show examples using both the `I18n.translate` method as well as the [`translate` view helper method](http://api.rubyonrails.org/classes/ActionView/Helpers/TranslationHelper.html#method-i-translate) (noting the additional feature provide by the view helper method).
|
||||
|
||||
Covered are features like these:
|
||||
|
||||
* looking up translations
|
||||
* interpolating data into translations
|
||||
* pluralizing translations
|
||||
* using safe HTML translations
|
||||
* using safe HTML translations (view helper method only)
|
||||
* localizing dates, numbers, currency, etc.
|
||||
|
||||
### Looking up Translations
|
||||
|
@ -585,6 +587,8 @@ you can look up the `books.index.title` value **inside** `app/views/books/index.
|
|||
<%= t '.title' %>
|
||||
```
|
||||
|
||||
NOTE: Automatic translation scoping by partial is only available from the `translate` view helper method.
|
||||
|
||||
### Interpolation
|
||||
|
||||
In many cases you want to abstract your translations so that **variables can be interpolated into the translation**. For this reason the I18n API provides an interpolation feature.
|
||||
|
@ -673,6 +677,8 @@ en:
|
|||
<div><%= t('title.html') %></div>
|
||||
```
|
||||
|
||||
NOTE: Automatic conversion to HTML safe translate text is only available from the `translate` view helper method.
|
||||
|
||||
![i18n demo html safe](images/i18n/demo_html_safe.png)
|
||||
|
||||
How to Store your Custom Translations
|
||||
|
|
|
@ -29,9 +29,42 @@ quickly.
|
|||
Launch!
|
||||
-------
|
||||
|
||||
Let's start to boot and initialize the app. It all begins with your app's
|
||||
`bin/rails` executable. A Rails application is usually started by running
|
||||
`rails console` or `rails server`.
|
||||
Let's start to boot and initialize the app. A Rails application is usually
|
||||
started by running `rails console` or `rails server`.
|
||||
|
||||
### `railties/bin/rails`
|
||||
|
||||
The `rails` in the command `rails server` is a ruby executable in your load
|
||||
path. This executable contains the following lines:
|
||||
|
||||
```ruby
|
||||
version = ">= 0"
|
||||
load Gem.bin_path('railties', 'rails', version)
|
||||
```
|
||||
|
||||
If you try out this command in a Rails console, you would see that this loads
|
||||
`railties/bin/rails`. A part of the file `railties/bin/rails.rb` has the
|
||||
following code:
|
||||
|
||||
```ruby
|
||||
require "rails/cli"
|
||||
```
|
||||
|
||||
The file `railties/lib/rails/cli` in turn calls
|
||||
`Rails::AppRailsLoader.exec_app_rails`.
|
||||
|
||||
### `railties/lib/rails/app_rails_loader.rb`
|
||||
|
||||
The primary goal of the function `exec_app_rails` is to execute your app's
|
||||
`bin/rails`. If the current directory does not have a `bin/rails`, it will
|
||||
navigate upwards until it finds a `bin/rails` executable. Thus one can invoke a
|
||||
`rails` command from anywhere inside a rails application.
|
||||
|
||||
For `rails server` the equivalent of the following command is executed:
|
||||
|
||||
```bash
|
||||
$ exec ruby bin/rails server
|
||||
```
|
||||
|
||||
### `bin/rails`
|
||||
|
||||
|
@ -54,7 +87,7 @@ The `APP_PATH` constant will be used later in `rails/commands`. The `config/boot
|
|||
# Set up gems listed in the Gemfile.
|
||||
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
||||
|
||||
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
|
||||
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
||||
```
|
||||
|
||||
In a standard Rails application, there's a `Gemfile` which declares all
|
||||
|
@ -121,7 +154,7 @@ when 'server'
|
|||
# Change to the application's path if there is no config.ru file in current directory.
|
||||
# This allows us to run `rails server` from other directories, but still get
|
||||
# the main config.ru and properly set the tmp directory.
|
||||
Dir.chdir(File.expand_path('../../', APP_PATH)) unless File.exists?(File.expand_path("config.ru"))
|
||||
Dir.chdir(File.expand_path('../../', APP_PATH)) unless File.exist?(File.expand_path("config.ru"))
|
||||
|
||||
require 'rails/commands/server'
|
||||
Rails::Server.new.tap do |server|
|
||||
|
|
|
@ -83,7 +83,7 @@ To use `rackup` instead of Rails' `rails server`, you can put the following insi
|
|||
# Rails.root/config.ru
|
||||
require ::File.expand_path('../config/environment', __FILE__)
|
||||
|
||||
use Rack::Debugger
|
||||
use Rails::Rack::Debugger
|
||||
use Rack::ContentLength
|
||||
run Rails.application
|
||||
```
|
||||
|
|
Loading…
Reference in a new issue