mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge docrails, resolving conflicts in the assets guide
This commit is contained in:
commit
abb0905404
9 changed files with 26 additions and 24 deletions
|
@ -315,7 +315,7 @@ end
|
|||
<ruby>
|
||||
class MyMigration < ActiveRecord::Migration
|
||||
def change
|
||||
create_table(:horses) do
|
||||
create_table(:horses) do |t|
|
||||
t.column :content, :text
|
||||
t.column :remind_at, :datetime
|
||||
end
|
||||
|
|
|
@ -684,9 +684,11 @@ end
|
|||
|
||||
This will read and stream the file 4kB at the time, avoiding loading the entire file into memory at once. You can turn off streaming with the +:stream+ option or adjust the block size with the +:buffer_size+ option.
|
||||
|
||||
If +:type+ is not specified, it will be guessed from the file extension specified in +:filename+. If the content type is not registered for the extension, <tt>application/octet-stream</tt> will be used.
|
||||
|
||||
WARNING: Be careful when using data coming from the client (params, cookies, etc.) to locate the file on disk, as this is a security risk that might allow someone to gain access to files they are not meant to see.
|
||||
|
||||
TIP: It is not recommended that you stream static files through Rails if you can instead keep them in a public folder on your web server. It is much more efficient to let the user download the file directly using Apache or another web server, keeping the request from unnecessarily going through the whole Rails stack. Although if you do need the request to go through Rails for some reason, you can set the +:x_sendfile+ option to true, and Rails will let the web server handle sending the file to the user, freeing up the Rails process to do other things. Note that your web server needs to support the +X-Sendfile+ header for this to work.
|
||||
TIP: It is not recommended that you stream static files through Rails if you can instead keep them in a public folder on your web server. It is much more efficient to let the user download the file directly using Apache or another web server, keeping the request from unnecessarily going through the whole Rails stack.
|
||||
|
||||
h4. RESTful Downloads
|
||||
|
||||
|
|
|
@ -163,12 +163,14 @@ person.first_name_changed? #=> true
|
|||
</ruby>
|
||||
|
||||
Track what was the previous value of the attribute.
|
||||
|
||||
<ruby>
|
||||
#attr_name_was accessor
|
||||
person.first_name_was #=> "First Name"
|
||||
</ruby>
|
||||
|
||||
Track both previous and current value of the changed attribute. Returns an array if changed else returns nil
|
||||
|
||||
<ruby>
|
||||
#attr_name_change
|
||||
person.first_name_change #=> ["First Name", "First Name 1"]
|
||||
|
|
|
@ -132,7 +132,7 @@ SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1
|
|||
|
||||
<tt>Model.last</tt> returns +nil+ if no matching record is found. No exception will be raised.
|
||||
|
||||
h5. +first!+
|
||||
h5(#first_1). +first!+
|
||||
|
||||
<tt>Model.first!</tt> finds the first record. For example:
|
||||
|
||||
|
@ -149,7 +149,7 @@ SELECT * FROM clients LIMIT 1
|
|||
|
||||
<tt>Model.first!</tt> raises +RecordNotFound+ if no matching record is found.
|
||||
|
||||
h5. +last!+
|
||||
h5(#last_1). +last!+
|
||||
|
||||
<tt>Model.last!</tt> finds the last record. For example:
|
||||
|
||||
|
|
|
@ -15,11 +15,11 @@ h3. What is the Asset Pipeline?
|
|||
|
||||
The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.
|
||||
|
||||
Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets. Rails 3.1 is integrated with Sprockets through ActionPack which depends on the +sprockets+ gem, by default.
|
||||
Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets. Rails 3.1 is integrated with Sprockets through Action Pack which depends on the +sprockets+ gem, by default.
|
||||
|
||||
By having this as a core feature of Rails, all developers can benefit from the power of having their assets pre-processed, compressed and minified by one central library, Sprockets. This is part of Rails' "Fast by default" strategy as outlined by DHH in his 2011 keynote at Railsconf.
|
||||
|
||||
In new Rails 3.1 application the asset pipeline is enabled by default. It can be disabled in +application.rb+ by putting this line inside the +Application+ class definition:
|
||||
In Rails 3.1, the asset pipeline is enabled by default. It can be disabled in +application.rb+ by putting this line inside the +Application+ class definition:
|
||||
|
||||
<plain>
|
||||
config.assets.enabled = false
|
||||
|
@ -308,7 +308,7 @@ NOTE: Under normal circumstances the default option should not be changed. If th
|
|||
|
||||
h4. Precompiling Assets
|
||||
|
||||
Rails comes bundled with a rake task to compile the asset manifests and other files in the pipeline to disc.
|
||||
Rails comes bundled with a rake task to compile the asset manifests and other files in the pipeline to the disk.
|
||||
|
||||
Compiled assets are written to the location specified in +config.assets.prefix+. The default setting will use the +public/assets+ directory.
|
||||
|
||||
|
@ -361,7 +361,7 @@ This can be changed with the +config.assets.manifest+ option. A fully specified
|
|||
config.assets.manifest = '/path/to/some/other/location'
|
||||
</erb>
|
||||
|
||||
NOTE: If there are missing precompiled files in production you will get an "AssetNoPrecompiledError" exception indicating the name of the missing file.
|
||||
NOTE: If there are missing precompiled files in production you will get an <tt>AssetNoPrecompiledError</tt> exception indicating the name of the missing file(s).
|
||||
|
||||
h5. Server Configuration
|
||||
|
||||
|
@ -385,7 +385,7 @@ For Apache:
|
|||
|
||||
TODO: nginx instructions
|
||||
|
||||
When files are precompiled, Sprockets also creates a "Gzip":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. This avoids the server having to do this for any requests; it can simply read the compressed files from disc. You must configure your server to use gzip compression and serve the compressed assets that will be stored in the +public/assets+ folder. The following configuration options can be used:
|
||||
When files are precompiled, Sprockets also creates a "Gzip":http://en.wikipedia.org/wiki/Gzip (.gz) version of your assets. This avoids the server having to do this for any requests; it can simply read the compressed files from disk. You must configure your server to use gzip compression and serve the compressed assets that will be stored in the +public/assets+ folder. The following configuration options can be used:
|
||||
|
||||
For Apache:
|
||||
|
||||
|
@ -419,7 +419,7 @@ location ~ ^/(assets)/ {
|
|||
|
||||
h4. Live Compilation
|
||||
|
||||
In some circumstances you may wish to use live compilation. In this mode all requests for assets in the Pipeline are handled by Sprockets directly.
|
||||
In some circumstances you may wish to use live compilation. In this mode all requests for assets in the pipeline are handled by Sprockets directly.
|
||||
|
||||
To enable this option set:
|
||||
|
||||
|
@ -437,7 +437,7 @@ h3. Customizing the Pipeline
|
|||
|
||||
h4. CSS Compression
|
||||
|
||||
There is currently one option for compressing CSS, YUI. This Gem extends the CSS syntax and offers minification.
|
||||
There is currently one option for compressing CSS, YUI. The "YUI CSS compressor":http://developer.yahoo.com/yui/compressor/css.html provides minification.
|
||||
|
||||
The following line enables YUI compression, and requires the +yui-compressor+ gem.
|
||||
|
||||
|
@ -445,7 +445,7 @@ The following line enables YUI compression, and requires the +yui-compressor+ ge
|
|||
config.assets.css_compressor = :yui
|
||||
</erb>
|
||||
|
||||
The +config.assets.compress+ must be set to +true+ to enable CSS compression
|
||||
The +config.assets.compress+ must be set to +true+ to enable CSS compression.
|
||||
|
||||
h4. JavaScript Compression
|
||||
|
||||
|
@ -539,8 +539,7 @@ config.assets.enabled = true
|
|||
config.assets.version = '1.0'
|
||||
|
||||
# Change the path that assets are served from
|
||||
# config.assets.prefix = "/assets"
|
||||
|
||||
# config.assets.prefix = "/assets"
|
||||
</erb>
|
||||
|
||||
In +development.rb+:
|
||||
|
@ -584,9 +583,8 @@ The following should also be added to +Gemfile+:
|
|||
# Gems used only for assets and not required
|
||||
# in production environments by default.
|
||||
group :assets do
|
||||
gem 'sass-rails', " ~> 3.1.0"
|
||||
gem 'sass-rails', "~> 3.1.0"
|
||||
gem 'coffee-rails', "~> 3.1.0"
|
||||
gem 'uglifier'
|
||||
end
|
||||
</plain>
|
||||
|
||||
|
|
|
@ -134,15 +134,15 @@ Rails 3.1, by default, is set up to use the +sprockets+ gem to manage assets wit
|
|||
|
||||
* +config.assets.prefix+ defines the prefix where assets are served from. Defaults to +/assets+.
|
||||
|
||||
* +config.assets.digest+ enables the use of MD5 fingerprints in asset names. Set to +true+ by default in +production.rb+
|
||||
* +config.assets.digest+ enables the use of MD5 fingerprints in asset names. Set to +true+ by default in +production.rb+.
|
||||
|
||||
* +config.assets.debug+ disables the concatenation and compression of assets. Set to +false+ by default in +development.rb+
|
||||
* +config.assets.debug+ disables the concatenation and compression of assets. Set to +false+ by default in +development.rb+.
|
||||
|
||||
* +config.assets.manifest+ defines the full path to be used for the asset precompiler's manifest file. Defaults to using +config.assets.prefix+
|
||||
* +config.assets.manifest+ defines the full path to be used for the asset precompiler's manifest file. Defaults to using +config.assets.prefix+.
|
||||
|
||||
* +config.assets.cache_store+ defines the cache store that Sprockets will use. The default is the Rails file store.
|
||||
|
||||
* +config.assets.version+ is an option string that is used in MD5 hash generation. This can be changed to force all files to be recompiled.
|
||||
* +config.assets.version+ is an option string that is used in MD5 hash generation. This can be changed to force all files to be recompiled.
|
||||
|
||||
* +config.assets.compile+ is a boolean that can be used to turn on live Sprockets compilation in production.
|
||||
|
||||
|
|
|
@ -592,7 +592,7 @@ class CreatePosts < ActiveRecord::Migration
|
|||
end
|
||||
</ruby>
|
||||
|
||||
The above migration creates a method name +change+ which will be called when you
|
||||
The above migration creates a method named +change+ which will be called when you
|
||||
run this migration. The action defined in that method is also reversible, which
|
||||
means Rails knows how to reverse the change made by this migration, in case you
|
||||
want to reverse it at later date. By default, when you run this migration it
|
||||
|
|
|
@ -515,7 +515,7 @@ h4. Using +redirect_to+
|
|||
Another way to handle returning responses to an HTTP request is with +redirect_to+. As you've seen, +render+ tells Rails which view (or other asset) to use in constructing a response. The +redirect_to+ method does something completely different: it tells the browser to send a new request for a different URL. For example, you could redirect from wherever you are in your code to the index of photos in your application with this call:
|
||||
|
||||
<ruby>
|
||||
redirect_to photos_path
|
||||
redirect_to photos_url
|
||||
</ruby>
|
||||
|
||||
You can use +redirect_to+ with any arguments that you could use with +link_to+ or +url_for+. In addition, there's a special redirect that sends the user back to the page they just came from:
|
||||
|
|
|
@ -207,7 +207,7 @@ GC Time measures the amount of time spent in GC for the performance test case.
|
|||
|
||||
h5. Metric Availability
|
||||
|
||||
h6. Benchmarking
|
||||
h6(#benchmarking_1). Benchmarking
|
||||
|
||||
|_.Interpreter|_.Wall Time|_.Process Time|_.CPU Time|_.User Time|_.Memory|_.Objects|_.GC Runs|_.GC Time|
|
||||
|_.MRI | yes | yes | yes | no | yes | yes | yes | yes |
|
||||
|
@ -215,7 +215,7 @@ h6. Benchmarking
|
|||
|_.Rubinius | yes | no | no | no | yes | yes | yes | yes |
|
||||
|_.JRuby | yes | no | no | yes | yes | yes | yes | yes |
|
||||
|
||||
h6. Profiling
|
||||
h6(#profiling_1). Profiling
|
||||
|
||||
|_.Interpreter|_.Wall Time|_.Process Time|_.CPU Time|_.User Time|_.Memory|_.Objects|_.GC Runs|_.GC Time|
|
||||
|_.MRI | yes | yes | no | no | yes | yes | yes | yes |
|
||||
|
|
Loading…
Reference in a new issue