From 826820fb7f3206892fe2d558a59e33b23e4fc358 Mon Sep 17 00:00:00 2001 From: Richard Hulse Date: Mon, 11 Jul 2011 19:52:36 +1200 Subject: [asset pipeline] more updates to docs --- railties/guides/source/asset_pipeline.textile | 68 +++++++++++++++++++-------- 1 file changed, 48 insertions(+), 20 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 563c1c79ae..1cefe29e5e 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -106,22 +106,48 @@ h4. Coding links to Assets To access assets, we can use the same tags that we are generally familiar with: +Sprockets does not add any new methods to require your assets, we still use the familiar +javascript_include_tag+ and +stylesheet_link_tag+. + + + <%= stylesheet_link_tag "application" %> + <%= javascript_include_tag "application" %> + + +In regular views you can access images in the +assets/images+ directory like this: + <%= image_tag "rails.png" %> -Providing that assets are enabled within our application (+config.assets.enabled+ in the current environment's file is not set to +false+), this file will be served by Sprockets unless a file at +public/assets/rails.png+ exists, in which case that file will be served. Alternatively, a file with an MD5 hash after its name such as +public/assets/rails-af27b6a414e6da00003503148be9b409.png+ will also be picked up by Sprockets. How these hashes are generated is covered in the "Production Assets":#production_assets section later on in this guide. +Images can be organized into directories if required, and this Just Works. + +Providing that assets are enabled within our application (+config.assets.enabled+ in the current environment's file is not set to +false+), this file will be served by Sprockets unless a file at +public/assets/rails.png+ exists, in which case that file will be served. + +Alternatively, a file with an MD5 hash after its name such as +public/assets/rails-af27b6a414e6da00003503148be9b409.png+ will also be picked up by Sprockets. How these hashes are generated is covered in the "Production Assets":#production_assets section later on in this guide. Otherwise, Sprockets will look through the available paths until it finds a file that matches the name and then will serve it, first looking in the application's assets directories and then falling back to the various engines of the application. -Sprockets does not add any new methods to require your assets, we still use the familiar +javascript_include_tag+ and +stylesheet_link_tag+. +h5. CSS and ERB - - <%= stylesheet_link_tag "application" %> - <%= javascript_include_tag "application" %> - +If you add an erb extension to a css asset: -These helpers (when the pipeline is on) are providing links to the compiled manifest with the specified name (or names). + +application.css.erb + + +then you can use the asset_path helper in your CSS rules: + + +.class{background-image:<%= asset_path 'image.png' %>} + + +This will write the path to any specified images in +/app/assets/images+ and its subdirectories. + +Note that the closing tag cannot be of the style '-%>'. + +h5. CSS and SCSS + +TODO: Sass-rails's handy +image_url+ helpers h4. Manifest Files and Directives @@ -177,8 +203,6 @@ Keep in mind that the order of these pre-processors is important. For example, i h3. In Development -TODO: Talk about: Rack::Cache's caching (used in dev and production. The only difference is hashing and headers). - In the development environment assets are compiled and cached on the first request after the server is started. Sprockets sets a +must-validate+ cache-control http header to reduce request overhead on subsequent requests - on these the browser gets a 304 (not-modified) response. If any of the files in the manifest have changed between requests, the server will respond with a new compiled file. @@ -225,19 +249,12 @@ Sprockets also sets the +Cache-Control+ http header to +max-age=31536000+. This This behavior is controlled by the setting of +config.action_controller.perform_caching+ setting in Rails (which is +true+ for production, +false+ for everything else). This value is propagated to Sprockets during initialization for use when action_controller is not available. -TODO: -describe each and the differences between: - * Sass-rails's handy +image_url+ helpers - * ERB pre-processing and +asset_path+ - h4. Precompiling assets Even though assets are served by Rack::Cache with far-future headers, in high traffic sites this may not be fast enough. Rails comes bundled with a rake task to compile the manifests to files on disc. These are located in the +public/assets+ directory where they will be served by your web server instead of the Rails application. -TODO: Add section about image assets - The rake task is: @@ -246,16 +263,22 @@ rake assets:precompile TODO: explain where to use this with Capistrano -TODO: talk about the +config.assets.precompile+ option and the default matcher for files: +The default matcher for compiling files is rather broad: -[ /\w+\.(?!js|css).+/, "application.js", "application.css" ] +[ /\w+\.(?!js|css).+/, /application.(css|js)$/ ] +In practice you may choose to narrow this to just the files that contain manifests: -Sprockets also creates a "gzip":http://en.wikipedia.org/wiki/Gzip (.gz) of your assets. This prevents your server from contently compressing your assets for each request. 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 are some configuration blocks that you can use for common servers. -NGINX & Apache examples? + +config.assets.precompile = ['application.js', 'application.css', 'admin.js', 'admin.css'] + +When files are precompiled Sprockets also creates "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: + +TODO: NGINX instructions +TODO: Apache instructions h3. Customizing The Pipeline @@ -321,6 +344,11 @@ config.assets.prefix = "/some_other_path" This is a handy option if you have any existing project (pre Rails 3.1) that already uses this path. +h3. How caching works + +Sprockets uses the default rails cache store to cache assets in dev and production. The only difference is filenames are fingerprinted and get far-future headers in production. + +TODO: Add more about changing the default store. h3. Adding Assets to Your Gems -- cgit v1.2.3 From 812950e027fd79820ad73f7025d3be94dde8b3ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hrvoje=20=C5=A0imi=C4=87?= Date: Mon, 11 Jul 2011 14:45:47 +0200 Subject: fixed paths, more consistent helpers and paths examples --- railties/guides/source/routing.textile | 96 +++++++++++++++++----------------- 1 file changed, 48 insertions(+), 48 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile index 1cbc5c8f6e..06b3579720 100644 --- a/railties/guides/source/routing.textile +++ b/railties/guides/source/routing.textile @@ -68,7 +68,7 @@ Rails would dispatch that request to the +destroy+ method on the +photos+ contro h4. CRUD, Verbs, and Actions -In Rails, a resourceful route provides a mapping between HTTP verbs and URLs and controller actions. By convention, each action also maps to particular CRUD operations in a database. A single entry in the routing file, such as +In Rails, a resourceful route provides a mapping between HTTP verbs and URLs to controller actions. By convention, each action also maps to particular CRUD operations in a database. A single entry in the routing file, such as resources :photos @@ -94,8 +94,8 @@ Creating a resourceful route will also expose a number of helpers to the control * +photos_path+ returns +/photos+ * +new_photo_path+ returns +/photos/new+ -* +edit_photo_path(id)+ returns +/photos/:id/edit+ (for instance, +edit_photo_path(10)+ returns +/photos/10/edit+) -* +photo_path(id)+ returns +/photos/:id+ (for instance, +photo_path(10)+ returns +/photos/10+) +* +edit_photo_path(:id)+ returns +/photos/:id/edit+ (for instance, +edit_photo_path(10)+ returns +/photos/10/edit+) +* +photo_path(:id)+ returns +/photos/:id+ (for instance, +photo_path(10)+ returns +/photos/10+) Each of these helpers has a corresponding +_url+ helper (such as +photos_url+) which returns the same path prefixed with the current host, port and path prefix. @@ -163,14 +163,14 @@ end This will create a number of routes for each of the +posts+ and +comments+ controller. For +Admin::PostsController+, Rails will create: -|_.HTTP Verb |_.Path |_.action |_.named helper | -|GET |/admin/posts |index | admin_posts_path | -|GET |/admin/posts/new |new | new_admin_posts_path | -|POST |/admin/posts |create | admin_posts_path | -|GET |/admin/posts/1 |show | admin_post_path(id) | -|GET |/admin/posts/1/edit |edit | edit_admin_post_path(id) | -|PUT |/admin/posts/1 |update | admin_post_path(id) | -|DELETE |/admin/posts/1 |destroy | admin_post_path(id) | +|_.HTTP Verb |_.Path |_.action |_.named helper | +|GET |/admin/posts |index | admin_posts_path | +|GET |/admin/posts/new |new | new_admin_post_path | +|POST |/admin/posts |create | admin_posts_path | +|GET |/admin/posts/:id |show | admin_post_path(:id) | +|GET |/admin/posts/:id/edit |edit | edit_admin_post_path(:id) | +|PUT |/admin/posts/:id |update | admin_post_path(:id) | +|DELETE |/admin/posts/:id |destroy | admin_post_path(:id) | If you want to route +/posts+ (without the prefix +/admin+) to +Admin::PostsController+, you could use @@ -204,12 +204,12 @@ In each of these cases, the named routes remain the same as if you did not use + |_.HTTP Verb |_.Path |_.action |_.named helper | |GET |/admin/posts |index | posts_path | -|GET |/admin/posts/new |new | posts_path | +|GET |/admin/posts/new |new | new_post_path | |POST |/admin/posts |create | posts_path | -|GET |/admin/posts/1 |show | post_path(id) | -|GET |/admin/posts/1/edit |edit | edit_post_path(id) | -|PUT |/admin/posts/1 |update | post_path(id) | -|DELETE |/admin/posts/1 |destroy | post_path(id) | +|GET |/admin/posts/:id |show | post_path(:id) | +|GET |/admin/posts/:id/edit|edit | edit_post_path(:id)| +|PUT |/admin/posts/:id |update | post_path(:id) | +|DELETE |/admin/posts/:id |destroy | post_path(:id) | h4. Nested Resources @@ -236,13 +236,13 @@ end In addition to the routes for magazines, this declaration will also route ads to an +AdsController+. The ad URLs require a magazine: |_.HTTP Verb |_.Path |_.action |_.used for | -|GET |/magazines/1/ads |index |display a list of all ads for a specific magazine | -|GET |/magazines/1/ads/new |new |return an HTML form for creating a new ad belonging to a specific magazine | -|POST |/magazines/1/ads |create |create a new ad belonging to a specific magazine | -|GET |/magazines/1/ads/1 |show |display a specific ad belonging to a specific magazine | -|GET |/magazines/1/ads/1/edit |edit |return an HTML form for editing an ad belonging to a specific magazine | -|PUT |/magazines/1/ads/1 |update |update a specific ad belonging to a specific magazine | -|DELETE |/magazines/1/ads/1 |destroy |delete a specific ad belonging to a specific magazine | +|GET |/magazines/:id/ads |index |display a list of all ads for a specific magazine | +|GET |/magazines/:id/ads/new |new |return an HTML form for creating a new ad belonging to a specific magazine | +|POST |/magazines/:id/ads |create |create a new ad belonging to a specific magazine | +|GET |/magazines/:id/ads/:id |show |display a specific ad belonging to a specific magazine | +|GET |/magazines/:id/ads/:id/edit |edit |return an HTML form for editing an ad belonging to a specific magazine | +|PUT |/magazines/:id/ads/:id |update |update a specific ad belonging to a specific magazine | +|DELETE |/magazines/:id/ads/:id |destroy |delete a specific ad belonging to a specific magazine | This will also create routing helpers such as +magazine_ads_url+ and +edit_magazine_ad_path+. These helpers take an instance of Magazine as the first parameter (+magazine_ads_url(@magazine)+). @@ -628,16 +628,16 @@ resources :photos, :controller => "images" will recognize incoming paths beginning with +/photos+ but route to the +Images+ controller: -|_.HTTP Verb |_.Path |_.action |_.named helper | -|GET |/photos |index | photos_path | -|GET |/photos/new |new | new_photo_path | -|POST |/photos |create | photos_path | -|GET |/photos/1 |show | photo_path(id) | -|GET |/photos/1/edit |edit | edit_photo_path(id) | -|PUT |/photos/1 |update | photo_path(id) | -|DELETE |/photos/1 |destroy | photo_path(id) | +|_.HTTP Verb |_.Path |_.action |_.named helper | +|GET |/photos |index | photos_path | +|GET |/photos/new |new | new_photo_path | +|POST |/photos |create | photos_path | +|GET |/photos/:id |show | photo_path(:id) | +|GET |/photos/:id/edit |edit | edit_photo_path(:id) | +|PUT |/photos/:id |update | photo_path(:id) | +|DELETE |/photos/:id |destroy | photo_path(:id) | -NOTE: Use +photos_path+, +new_photos_path+, etc. to generate paths for this resource. +NOTE: Use +photos_path+, +new_photo_path+, etc. to generate paths for this resource. h4. Specifying Constraints @@ -672,14 +672,14 @@ resources :photos, :as => "images" will recognize incoming paths beginning with +/photos+ and route the requests to +PhotosController+, but use the value of the :as option to name the helpers. -|_.HTTP verb|_.Path |_.action |_.named helper | -|GET |/photos |index | images_path | -|GET |/photos/new |new | new_image_path | -|POST |/photos |create | images_path | -|GET |/photos/1 |show | image_path(id) | -|GET |/photos/1/edit |edit | edit_image_path(id) | -|PUT |/photos/1 |update | image_path(id) | -|DELETE |/photos/1 |destroy | image_path(id) | +|_.HTTP verb|_.Path |_.action |_.named helper | +|GET |/photos |index | images_path | +|GET |/photos/new |new | new_image_path | +|POST |/photos |create | images_path | +|GET |/photos/:id |show | image_path(:id) | +|GET |/photos/:id/edit |edit | edit_image_path(:id) | +|PUT |/photos/:id |update | image_path(:id) | +|DELETE |/photos/:id |destroy | image_path(:id) | h4. Overriding the +new+ and +edit+ Segments @@ -776,14 +776,14 @@ end Rails now creates routes to the +CategoriesController+. -|_.HTTP verb|_.Path |_.action |_.named helper | -|GET |/kategorien |index | categories_path | -|GET |/kategorien/neu |new | new_category_path | -|POST |/kategorien |create | categories_path | -|GET |/kategorien/1 |show | category_path(id) | -|GET |/kategorien/1/bearbeiten |edit | edit_category_path(id) | -|PUT |/kategorien/1 |update | category_path(id) | -|DELETE |/kategorien/1 |destroy | category_path(id) | +|_.HTTP verb|_.Path |_.action |_.named helper | +|GET |/kategorien |index | categories_path | +|GET |/kategorien/neu |new | new_category_path | +|POST |/kategorien |create | categories_path | +|GET |/kategorien/:id |show | category_path(:id) | +|GET |/kategorien/:id/bearbeiten |edit | edit_category_path(:id) | +|PUT |/kategorien/:id |update | category_path(:id) | +|DELETE |/kategorien/:id |destroy | category_path(:id) | h4. Overriding the Singular Form -- cgit v1.2.3 From eb716f630771cd4ffde8aa9bff79301822cb4b2b Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 12 Jul 2011 09:37:55 -0400 Subject: grammar/tense correction to rails application doc --- railties/lib/rails/application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index fe29668c72..692f8f546f 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -11,7 +11,7 @@ module Rails # == Initialization # # Rails::Application is responsible for executing all railties, engines and plugin - # initializers. Besides, it also executed some bootstrap initializers (check + # initializers. It also executes some bootstrap initializers (check # Rails::Application::Bootstrap) and finishing initializers, after all the others # are executed (check Rails::Application::Finisher). # -- cgit v1.2.3 From 2f30fb03bb90a624fa36e9142e76c15788dd5048 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 12 Jul 2011 09:54:43 -0400 Subject: misc grammar and clarity changes for rails/engine docs --- railties/lib/rails/engine.rb | 55 +++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 26 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index eb6fcd5dd7..556aed19cf 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -5,13 +5,14 @@ require 'rbconfig' require 'rails/engine/railties' module Rails - # Rails::Engine allows you to wrap a specific Rails application and share it across - # different applications. Since Rails 3.0, every Rails::Application is nothing - # more than an engine, allowing you to share it very easily. + # Rails::Engine allows you to wrap a specific Rails application or subset of + # functionality and share it with other applications. Since Rails 3.0, every + # Rails::Application is just an engine, which allows for simple + # feature and application sharing. # - # Any Rails::Engine is also a Rails::Railtie, so the same methods - # (like rake_tasks and +generators+) and configuration available in the - # latter can also be used in the former. + # Any Rails::Engine is also a Rails::Railtie, so the same + # methods (like rake_tasks and +generators+) and configuration + # options that are available in railties can also be used in engines. # # == Creating an Engine # @@ -71,12 +72,13 @@ module Rails # # == Paths # - # Since Rails 3.0, both your application and engines do not have hardcoded paths. - # This means that you are not required to place your controllers at app/controllers, - # but in any place which you find convenient. + # Since Rails 3.0, applications and engines have more flexible path configuration (as + # opposed to the previous hardcoded path configuration). This means that you are not + # required to place your controllers at app/controllers, but in any place + # which you find convenient. # # For example, let's suppose you want to place your controllers in lib/controllers. - # All you would need to do is: + # You can set that as an option: # # class MyEngine < Rails::Engine # paths["app/controllers"] = "lib/controllers" @@ -105,9 +107,9 @@ module Rails # paths["config/routes"] # => ["config/routes.rb"] # end # - # Your Application class adds a couple more paths to this set. And as in your - # Application,all folders under +app+ are automatically added to the load path. - # So if you have app/observers, it's added by default. + # The Application class adds a couple more paths to this set. And as in your + # Application, all folders under +app+ are automatically added to the load path. + # If you have an app/observers folder for example, it will be added by default. # # == Endpoint # @@ -130,8 +132,8 @@ module Rails # # == Middleware stack # - # As an engine can now be rack endpoint, it can also have a middleware stack. The usage is exactly - # the same as in Application: + # As an engine can now be a rack endpoint, it can also have a middleware + # stack. The usage is exactly the same as in Application: # # module MyEngine # class Engine < Rails::Engine @@ -141,8 +143,8 @@ module Rails # # == Routes # - # If you don't specify an endpoint, routes will be used as the default endpoint. You can use them - # just like you use an application's routes: + # If you don't specify an endpoint, routes will be used as the default + # endpoint. You can use them just like you use an application's routes: # # # ENGINE/config/routes.rb # MyEngine::Engine.routes.draw do @@ -191,8 +193,8 @@ module Rails # == Isolated Engine # # Normally when you create controllers, helpers and models inside an engine, they are treated - # as they were created inside the application. This means all application helpers and named routes - # will be available to your engine's controllers. + # as if they were created inside the application itself. This means that all helpers and + # named routes from the application will be available to your engine's controllers as well. # # However, sometimes you want to isolate your engine from the application, especially if your engine # has its own router. To do that, you simply need to call +isolate_namespace+. This method requires @@ -240,9 +242,9 @@ module Rails # text_field :title # => # end # - # Additionally an isolated engine will set its name according to namespace, so + # Additionally, an isolated engine will set its name according to namespace, so # MyEngine::Engine.engine_name will be "my_engine". It will also set MyEngine.table_name_prefix - # to "my_engine_", changing MyEngine::Article model to use my_engine_article table. + # to "my_engine_", changing the MyEngine::Article model to use the my_engine_article table. # # == Using Engine's routes outside Engine # @@ -274,12 +276,13 @@ module Rails # end # end # - # Note that the :as option given to mount takes the engine_name as default, so most of the time + # Note that the :as option given to mount takes the engine_name as default, so most of the time # you can simply omit it. # - # Finally, if you want to generate a url to an engine's route using polymorphic_url, you also need - # to pass the engine helper. Let's say that you want to create a form pointing to one of the - # engine's routes. All you need to do is pass the helper as the first element in array with + # Finally, if you want to generate a url to an engine's route using + # polymorphic_url, you also need to pass the engine helper. Let's + # say that you want to create a form pointing to one of the engine's routes. + # All you need to do is pass the helper as the first element in array with # attributes for url: # # form_for([my_engine, @user]) @@ -319,7 +322,7 @@ module Rails # # Note that some of the migrations may be skipped if a migration with the same name already exists # in application. In such a situation you must decide whether to leave that migration or rename the - # migration in application and rerun copying migrations. + # migration in the application and rerun copying migrations. # # If your engine has migrations, you may also want to prepare data for the database in # the seeds.rb file. You can load that data using the load_seed method, e.g. -- cgit v1.2.3 From 85dd1dd663a8efac97e4d6a5dc33b23f1a75dc52 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 12 Jul 2011 10:20:42 -0400 Subject: grammar correction for rails/paths #add method arguments --- railties/lib/rails/paths.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index 09ff0ef378..6aecebe273 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -31,8 +31,8 @@ module Rails # root.add "config/routes", :with => "config/routes.rb" # root["config/routes"].inspect # => ["config/routes.rb"] # - # #add also accepts the following options as argument: eager_load, autoload, - # autoload_once and glob. + # The #add method accepts the following options as arguments: + # eager_load, autoload, autoload_once and glob. # # Finally, the Path object also provides a few helpers: # -- cgit v1.2.3 From 991678c1df4206f108ffd107a0c98420e2fbbbce Mon Sep 17 00:00:00 2001 From: Aslam Najeebdeen Date: Wed, 13 Jul 2011 13:33:32 +0530 Subject: Replaced appropriate word. --- railties/guides/source/migrations.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile index dbbf8f3b51..7e71a5048d 100644 --- a/railties/guides/source/migrations.textile +++ b/railties/guides/source/migrations.textile @@ -17,7 +17,7 @@ endprologue. h3. Anatomy of a Migration -Before I dive into the details of a migration, here are a few examples of the sorts of things you can do: +Before we dive into the details of a migration, here are a few examples of the sorts of things you can do: class CreateProducts < ActiveRecord::Migration -- cgit v1.2.3 From 5dcebd7e3803c34b7e1aa1ed3577c9851dbee4a4 Mon Sep 17 00:00:00 2001 From: Richard Hulse Date: Wed, 13 Jul 2011 21:20:53 +1200 Subject: [asset pipeline] add capistrano task Task still needs to symlink default rails default filestore location, but code may still be settling --- railties/guides/source/asset_pipeline.textile | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 1cefe29e5e..640d02f6c1 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -261,7 +261,21 @@ The rake task is: rake assets:precompile -TODO: explain where to use this with Capistrano +You can run this as part of a Capistrano deployment: + + +before "deploy:symlink", "deploy:precompile_assets" + +desc "Compile pipeline assets" +task :precompile_assets do + run "#{release_path}; RAILS_ENV=#{rails_env} bundle exec rake assets:precompile" +end + + +If you are not precompiling your assets, and you are using the default cache file store (which is the filesystem), you will need to symlink +rails_root/tmp/cache/assets+ from the shared folder that is part of the Capistrano deployment structure. This is so the cached file persist between deployments. + +TODO: Extend above task to allow for this and add task to set it up (See commits 8f0e0b6 and 704ee0df). + The default matcher for compiling files is rather broad: -- cgit v1.2.3 From 651cabc69a6cd661bc33824b995c2242fb65befe Mon Sep 17 00:00:00 2001 From: Daniel Dyba Date: Wed, 29 Jun 2011 23:04:02 -0700 Subject: Modified Migrations file --- railties/guides/source/migrations.textile | 39 +++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile index dbbf8f3b51..eae337b67b 100644 --- a/railties/guides/source/migrations.textile +++ b/railties/guides/source/migrations.textile @@ -117,6 +117,33 @@ Occasionally you will make a mistake when writing a migration. If you have alrea In general editing existing migrations is not a good idea: you will be creating extra work for yourself and your co-workers and cause major headaches if the existing version of the migration has already been run on production machines. Instead you should write a new migration that performs the changes you require. Editing a freshly generated migration that has not yet been committed to source control (or more generally which has not been propagated beyond your development machine) is relatively harmless. +h4. Supported Types + +Active Record supports the following types: + +* +:primary_key+ +* +:string+ +* +:text+ +* +:integer+ +* +:float+ +* +:decimal+ +* +:datetime+ +* +:timestamp+ +* +:time+ +* +:date+ +* +:binary+ +* +:boolean+ + +These will be mapped onto an appropriate underlying database type, for example with MySQL +:string+ is mapped to +VARCHAR(255)+. You can create columns of types not supported by Active Record when using the non-sexy syntax, for example + + +create_table :products do |t| + t.column :name, 'polygon', :null => false +end + + +This may however hinder portability to other databases. + h3. Creating a Migration h4. Creating a Model @@ -261,18 +288,6 @@ end will append +ENGINE=BLACKHOLE+ to the SQL statement used to create the table (when using MySQL the default is +ENGINE=InnoDB+). -The types supported by Active Record are +:primary_key+, +:string+, +:text+, +:integer+, +:float+, +:decimal+, +:datetime+, +:timestamp+, +:time+, +:date+, +:binary+, +:boolean+. - -These will be mapped onto an appropriate underlying database type, for example with MySQL +:string+ is mapped to +VARCHAR(255)+. You can create columns of types not supported by Active Record when using the non-sexy syntax, for example - - -create_table :products do |t| - t.column :name, 'polygon', :null => false -end - - -This may however hinder portability to other databases. - h4. Changing Tables A close cousin of +create_table+ is +change_table+, used for changing existing tables. It is used in a similar fashion to +create_table+ but the object yielded to the block knows more tricks. For example -- cgit v1.2.3 From cd8530db3c9930eb3c989ea6ad0cc57fa1821c18 Mon Sep 17 00:00:00 2001 From: joeellis Date: Thu, 14 Jul 2011 09:17:29 -0700 Subject: Minor grammar mistake --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 640d02f6c1..522a223c4b 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -100,7 +100,7 @@ Assets can be placed inside an application in one of three locations: +app/asset +vendor/assets+ is for assets that are owned by outside entities, such as code for JavaScript plugins. -All subdirectories that exists within these three locations will be added to the search path for Sprockets (visible by calling +Rails.application.config.assets.paths+ in a console). When an asset is requested, these paths will be looked through to see if they contain an asset matching the name specified. Once an asset has been found, it's processed by Sprockets and served. +All subdirectories that exist within these three locations will be added to the search path for Sprockets (visible by calling +Rails.application.config.assets.paths+ in a console). When an asset is requested, these paths will be looked through to see if they contain an asset matching the name specified. Once an asset has been found, it's processed by Sprockets and served. h4. Coding links to Assets -- cgit v1.2.3 From 28d5d22f5a1e3a535d86ad06f4dc8220e61a8d64 Mon Sep 17 00:00:00 2001 From: Richard Hulse Date: Fri, 15 Jul 2011 16:19:11 +1200 Subject: [asset pipeline] Added information about data uri helper See Sprockets issue 111 and Sprockets commit cd38a1670a --- railties/guides/source/asset_pipeline.textile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 522a223c4b..aca3c51db5 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -127,6 +127,15 @@ Alternatively, a file with an MD5 hash after its name such as +public/assets/rai Otherwise, Sprockets will look through the available paths until it finds a file that matches the name and then will serve it, first looking in the application's assets directories and then falling back to the various engines of the application. +If you want to use a "css data uri":http://en.wikipedia.org/wiki/Data_URI_scheme - a method of embedding the image data directly into the CSS file - you can use the +asset_data_uri+ helper. + + + #logo { background: url(<%= asset_data_uri 'logo.png' %>) + + +This will insert a correctly formatted data uri into the CSS source. + + h5. CSS and ERB If you add an erb extension to a css asset: @@ -272,7 +281,7 @@ task :precompile_assets do end -If you are not precompiling your assets, and you are using the default cache file store (which is the filesystem), you will need to symlink +rails_root/tmp/cache/assets+ from the shared folder that is part of the Capistrano deployment structure. This is so the cached file persist between deployments. +If you are not precompiling your assets, and you are using the default cache file store (which is the filesystem), you will need to symlink +rails_root/tmp/cache/assets+ from the shared folder that is part of the Capistrano deployment structure. This is so the cached file persist between deployments. TODO: Extend above task to allow for this and add task to set it up (See commits 8f0e0b6 and 704ee0df). -- cgit v1.2.3 From 0894d73c7552a4c7d576b7d3692c6a18faadd273 Mon Sep 17 00:00:00 2001 From: Hendy Tanata Date: Fri, 15 Jul 2011 21:56:03 +0800 Subject: Fix wildcard route code examples. Should be "match" instead of "map". --- railties/guides/source/routing.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile index 06b3579720..57e390f385 100644 --- a/railties/guides/source/routing.textile +++ b/railties/guides/source/routing.textile @@ -560,13 +560,13 @@ would match +zoo/woo/foo/bar/baz+ with +params[:a]+ equals +"zoo/woo"+, and +par NOTE: Starting from Rails 3.1, wildcard routes will always match the optional format segment by default. For example if you have this route: -map '*pages' => 'pages#show' +match '*pages' => 'pages#show' NOTE: By requesting +"/foo/bar.json"+, your +params[:pages]+ will be equals to +"foo/bar"+ with the request format of JSON. If you want the old 3.0.x behavior back, you could supply +:format => false+ like this: -map '*pages' => 'pages#show', :format => false +match '*pages' => 'pages#show', :format => false h4. Redirection -- cgit v1.2.3 From ff410c4ea9ea54b3f4b9d5838703a4b039a1cf3f Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Fri, 15 Jul 2011 23:06:37 +0530 Subject: Revert "Fix wildcard route code examples." This reverts commit 0894d73c7552a4c7d576b7d3692c6a18faadd273. Reason: CHANGELOGs should not be changed in docrails. --- railties/guides/source/routing.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile index 57e390f385..06b3579720 100644 --- a/railties/guides/source/routing.textile +++ b/railties/guides/source/routing.textile @@ -560,13 +560,13 @@ would match +zoo/woo/foo/bar/baz+ with +params[:a]+ equals +"zoo/woo"+, and +par NOTE: Starting from Rails 3.1, wildcard routes will always match the optional format segment by default. For example if you have this route: -match '*pages' => 'pages#show' +map '*pages' => 'pages#show' NOTE: By requesting +"/foo/bar.json"+, your +params[:pages]+ will be equals to +"foo/bar"+ with the request format of JSON. If you want the old 3.0.x behavior back, you could supply +:format => false+ like this: -match '*pages' => 'pages#show', :format => false +map '*pages' => 'pages#show', :format => false h4. Redirection -- cgit v1.2.3 From b6d5612f551e982441097a67df001b5da99dee58 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Fri, 15 Jul 2011 23:56:58 +0530 Subject: Should be "match" instead of "map" --- railties/guides/source/routing.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile index 06b3579720..57e390f385 100644 --- a/railties/guides/source/routing.textile +++ b/railties/guides/source/routing.textile @@ -560,13 +560,13 @@ would match +zoo/woo/foo/bar/baz+ with +params[:a]+ equals +"zoo/woo"+, and +par NOTE: Starting from Rails 3.1, wildcard routes will always match the optional format segment by default. For example if you have this route: -map '*pages' => 'pages#show' +match '*pages' => 'pages#show' NOTE: By requesting +"/foo/bar.json"+, your +params[:pages]+ will be equals to +"foo/bar"+ with the request format of JSON. If you want the old 3.0.x behavior back, you could supply +:format => false+ like this: -map '*pages' => 'pages#show', :format => false +match '*pages' => 'pages#show', :format => false h4. Redirection -- cgit v1.2.3 From 765b79257a3eab2063cbf44eba6d9a405c488b0b Mon Sep 17 00:00:00 2001 From: John Warwick Date: Fri, 15 Jul 2011 22:40:17 -0400 Subject: Fixing typo in plugins.textile --- railties/guides/source/plugins.textile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/plugins.textile b/railties/guides/source/plugins.textile index 79bbe495bd..188423861d 100644 --- a/railties/guides/source/plugins.textile +++ b/railties/guides/source/plugins.textile @@ -86,7 +86,7 @@ class CoreExtTest < Test::Unit::TestCase end -Run +rake+ to run the test. This test should fail because we haven't implemented the +to_squak+ method: +Run +rake+ to run the test. This test should fail because we haven't implemented the +to_squawk+ method: 1) Error: @@ -218,8 +218,8 @@ test/dummy directory: $ cd test/dummy -$ rails generate model Hickwall last_squak:string -$ rails generate model Wickwall last_squak:string last_tweet:string +$ rails generate model Hickwall last_squawk:string +$ rails generate model Wickwall last_squawk:string last_tweet:string Now you can create the necessary database tables in your testing database by navigating to your dummy app -- cgit v1.2.3 From 0f78aeee87c25bb8fb864daf0f0a1b2bf7a241ac Mon Sep 17 00:00:00 2001 From: Richard Hulse Date: Sat, 16 Jul 2011 19:02:40 +1200 Subject: [asset pipeline] Add section on sendfile option This option has caught a few people out, so it is a good idea to include an explanation and a Gotcha. See Rails bug 1822 See 1822 comment 1585926 for resolution --- railties/guides/source/asset_pipeline.textile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index aca3c51db5..bd7319d331 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -367,6 +367,20 @@ config.assets.prefix = "/some_other_path" This is a handy option if you have any existing project (pre Rails 3.1) that already uses this path. +h4. X-Sendfile headers + +The X-Sendfile header is a directive to the server to ignore the response from the application, and instead serve the file specified in the headers. In production Rails (via Sprockets) does not send the asset - just the location and a zero-length response - relying on the server to do work. Files are faster served by the webserver. Both Apache and nginx support this option. + +New applications contain this line in +production.rb+ + + +config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx + + +You should check that your server or hosting service actually supports this, otherwise comment it out. + +Gotcha: If you are upgrading an existing application and intend to use this option, take care to paste this configuration option only into +production.rb+ (and not +application.rb+ ). + h3. How caching works Sprockets uses the default rails cache store to cache assets in dev and production. The only difference is filenames are fingerprinted and get far-future headers in production. -- cgit v1.2.3 From 86869a09eec2eac76e57c04b785c9b4443ad2c72 Mon Sep 17 00:00:00 2001 From: Richard Hulse Date: Sun, 17 Jul 2011 14:19:04 +1200 Subject: [asset pipeline] A few corrections and some new material Add notes about capistrano task being added to that project and correction to information about precompilation. --- railties/guides/source/asset_pipeline.textile | 30 ++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index bd7319d331..01ccabda87 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -283,24 +283,44 @@ end If you are not precompiling your assets, and you are using the default cache file store (which is the filesystem), you will need to symlink +rails_root/tmp/cache/assets+ from the shared folder that is part of the Capistrano deployment structure. This is so the cached file persist between deployments. -TODO: Extend above task to allow for this and add task to set it up (See commits 8f0e0b6 and 704ee0df). +TODO: Extend above task to allow for this and add task to set it up (See commits 8f0e0b6 and 704ee0df). Note: Capistrano folks are working on a recipe - update this when it available (see https://github.com/capistrano/capistrano/pull/35). - -The default matcher for compiling files is rather broad: +The default matcher for compiling files will include +application.js+, +application.css+ and all files that do not end in +js+ or +css+: [ /\w+\.(?!js|css).+/, /application.(css|js)$/ ] -In practice you may choose to narrow this to just the files that contain manifests: +If you have other manifests or individual stylesheet and javascript files to include, you can append them to the +precompile+ array: -config.assets.precompile = ['application.js', 'application.css', 'admin.js', 'admin.css'] +config.assets.precompile << ['admin.js', 'admin.css', 'swfObject.js'] +Precompiled assets exist on the filesystem and are served directly by your webserver. They do not have far-future headers by default, so to get the benefit of fingerprinting you'll have to update your server configuration to add them. + +For Apache: + + + + # Some browsers still send conditional-GET requests if there's a + # Last-Modified header or an ETag header even if they haven't + # reached the expiry date sent in the Expires header. + Header unset Last-Modified + Header unset ETag + FileETag None + # RFC says only cache for 1 year + ExpiresActive On + ExpiresDefault "access plus 1 year" + + + +TODO: NGINX instructions + When files are precompiled Sprockets also creates "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: TODO: NGINX instructions + TODO: Apache instructions -- cgit v1.2.3 From ade629e206d17c2aa321de9c53a0a68310e2f865 Mon Sep 17 00:00:00 2001 From: Sam Umbach Date: Sat, 16 Jul 2011 21:02:36 -0700 Subject: Fix typo --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 01ccabda87..925f95eaac 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -44,7 +44,7 @@ h4. What is fingerprinting and why should I care? Fingerprinting is a technique where the filenames of content that is static or infrequently updated is altered to be unique to the content contained in the file. -When a filename is unique and based on its content, http headers can be set to encourage caches everywhere (at ISPs, in browsers) to keep there own copy of the content. When the content is updated, the fingerprint will change and the remote clients will request the new file. This is generally known as _cachebusting_. +When a filename is unique and based on its content, http headers can be set to encourage caches everywhere (at ISPs, in browsers) to keep their own copy of the content. When the content is updated, the fingerprint will change and the remote clients will request the new file. This is generally known as _cachebusting_. The most effective technique is to insert a hash of the content into the name, usually at the end. For example a CSS file +global.css+ is hashed and the filename is updated to incorporate the hash. -- cgit v1.2.3 From bae54c5430847ea5c3b71ae2d28d30f77628cc88 Mon Sep 17 00:00:00 2001 From: Sam Umbach Date: Sat, 16 Jul 2011 21:08:14 -0700 Subject: Switch Tilt link to Textile format --- railties/guides/source/asset_pipeline.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 925f95eaac..91285eec6c 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -415,6 +415,6 @@ A good example of this is the +jquery-rails+ gem which comes with Rails as the s h3. Making Your Library or Gem a Pre-Processor -"You should be able to register [your gems] on Tilt and Sprockets will find them." - Josh -Tilt: https://github.com/rtomayko/tilt +"You should be able to register [your gems] on "Tilt":Tilt and Sprockets will find them." - Josh +[Tilt]https://github.com/rtomayko/tilt -- cgit v1.2.3 From 602bac19e75347d642c7f5b86ff46dae2c32c4e5 Mon Sep 17 00:00:00 2001 From: Richard Hulse Date: Sun, 17 Jul 2011 20:12:30 +1200 Subject: [configuring] add doc for missing assets attribute .compress turns on the compression using the types specified in other config options --- railties/guides/source/configuring.textile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index 8e6010ff79..7ed958be08 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -120,10 +120,12 @@ h4. Configuring Assets Rails 3.1, by default, is set up to use the +sprockets+ gem to manage assets within an application. This gem concatenates and compresses assets in order to make serving them much less painful. -* +config.assets.css_compressor+ defines the CSS compressor to use. Only supported value at the moment is +:yui+, which uses the +yui-compressor+ gem. - * +config.assets.enabled+ a flag that controls whether the asset pipeline is enabled. It is explicitly initialized in +config/application.rb+. +* +config.assets.compress+ a flag that enables the compression of compiled assets. It is explicitly set to true in +config/production.rb+. + +* +config.assets.css_compressor+ defines the CSS compressor to use. Only supported value at the moment is +:yui+, which uses the +yui-compressor+ gem. + * +config.assets.js_compressor+ defines the JavaScript compressor to use. Possible values are +:closure+, +:uglifier+ and +:yui+ which require the use of the +closure-compiler+, +uglifier+ or +yui-compressor+ gems respectively. * +config.assets.paths+ contains the paths which are used to look for assets. Appending paths to this configuration option will cause those paths to be used in the search for assets. -- cgit v1.2.3 From 5187264e19df0bb0e36150803e3c69b2e0e26a74 Mon Sep 17 00:00:00 2001 From: Richard Hulse Date: Sun, 17 Jul 2011 20:22:01 +1200 Subject: [asset pipeline] Correct CSS section and include Gem details Also added note about compress option, which was not mentioned anywhere and is required --- railties/guides/source/asset_pipeline.textile | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 91285eec6c..4a1c623436 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -326,33 +326,32 @@ TODO: Apache instructions h3. Customizing The Pipeline -h4. CSS -There is currently one option for processing CSS - SCSS. This Gem extends the CSS syntax and offers minification. +h4. CSS Compression -The following line will enable SCSS in you project. +There is currently one option for compressing CSS - YUI. This Gem extends the CSS syntax and offers minification. + +The following line will enable YUI compression, and requires the +yui-compressor+ gem. -config.assets.css_compressor = :scss +config.assets.css_compressor = :yui -This option is for compression only and does not relate to the SCSS language extensions that apply when using the +.scss+ file extension on CSS assets. +The +config.assets.compress+ must be set to +true+ to enable CSS compression h4. Javascript -There are three options available to process javascript - uglifier, closure and yui. +Possible options for Javascript compression are +:closure+, +:uglifier+ and +:yui+. These require the use of the +closure-compiler+, +uglifier+ or +yui-compressor+ gems respectively. The default Gemfile includes "uglifier":https://github.com/lautis/uglifier. This gem wraps "UglifierJS":https://github.com/mishoo/UglifyJS (written for NodeJS) in Ruby. It compress your code by removing white spaces and other magical things like changing your if and else statements to ternary operators when possible. -TODO: Add detail about the other two - The following line will invoke uglifier for Javascript compression. config.assets.js_compressor = :uglifier - +The +config.assets.compress+ must be set to +true+ to enable Javascript compression h4. Using your own compressor @@ -418,3 +417,4 @@ h3. Making Your Library or Gem a Pre-Processor "You should be able to register [your gems] on "Tilt":Tilt and Sprockets will find them." - Josh [Tilt]https://github.com/rtomayko/tilt + -- cgit v1.2.3 From 98df4983b3ed332a6164f14d2ffc273adf7ca5a8 Mon Sep 17 00:00:00 2001 From: Ray Baxter Date: Sun, 17 Jul 2011 13:22:15 -0700 Subject: Add seach, tel, url and email inputs as 'Other Helpers of Interest' --- railties/guides/source/form_helpers.textile | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile index 9051ede9dd..e10620272b 100644 --- a/railties/guides/source/form_helpers.textile +++ b/railties/guides/source/form_helpers.textile @@ -170,12 +170,16 @@ IMPORTANT: Always use labels for each checkbox and radio button. They associate h4. Other Helpers of Interest -Other form controls worth mentioning are the text area, password input and hidden input: +Other form controls worth mentioning are the text area, password input, hidden input, search input, tel input, url input and email input: <%= text_area_tag(:message, "Hi, nice site", :size => "24x6") %> <%= password_field_tag(:password) %> <%= hidden_field_tag(:parent_id, "5") %> +<%= search_field(:user, :name) %> +<%= telephone_field(:user, :phone) %> +<%= url_field(:user, "homepage) %> +<%= email_field(:user, :address) %> output: @@ -184,13 +188,17 @@ output: + + + + -Hidden inputs are not shown to the user, but they hold data like any textual input. Values inside them can be changed with JavaScript. +Hidden inputs are not shown to the user, but they hold data like any textual input. Values inside them can be changed with JavaScript. The search, tel, url and email inputs are specified in HTML5 and may receive special handling and/or formatting +in some user-agents. TIP: If you're using password input fields (for any purpose), you might want to configure your application to prevent those parameters from being logged. - h3. Dealing with Model Objects h4. Model Object Helpers -- cgit v1.2.3 From 27b1bf3c1f74c9f4fd43749a319d8ff8fe8be326 Mon Sep 17 00:00:00 2001 From: Richard Hulse Date: Mon, 18 Jul 2011 11:02:46 +1200 Subject: [asset pipeline] update capistrano task code This code actually works. --- railties/guides/source/asset_pipeline.textile | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 4a1c623436..652ced480f 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -273,11 +273,8 @@ rake assets:precompile You can run this as part of a Capistrano deployment: -before "deploy:symlink", "deploy:precompile_assets" - -desc "Compile pipeline assets" -task :precompile_assets do - run "#{release_path}; RAILS_ENV=#{rails_env} bundle exec rake assets:precompile" +before 'deploy:symlink' do + run "cd #{release_path}; RAILS_ENV=#{rails_env} rake assets:precompile" end -- cgit v1.2.3 From 2f69469479e4fe51748e714fadcfdf30d111d5e5 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Mon, 18 Jul 2011 16:26:15 +1000 Subject: Complete another review of asset pipeline guide --- railties/guides/source/asset_pipeline.textile | 67 +++++++++++++-------------- 1 file changed, 32 insertions(+), 35 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 652ced480f..f3dbd108cc 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -30,13 +30,11 @@ It is recommended that you use the defaults for all new apps. h4. Main Features -The first is to concatenate of assets. This is important in a production environment to reduce the number of requests that a client browser has to make to render a web page. While Rails already has a feature to concatenate these types of asset--by placing +:cache => true+ at the end of tags such as +javascript_include_tag+ and +stylesheet_link_tag+--, many people do not use it. +The first feature of the pipeline is to concatenate assets. This is important in a production environment, as it reduces the number of requests that a browser needs to make to render a web page. While Rails already has a feature to concatenate these types of asset--by placing +:cache => true+ at the end of tags such as +javascript_include_tag+ and +stylesheet_link_tag+--, many people do not use it. -The default behavior in Rails 3.1 and onward is to concatenate all files into one master file each for JS and CSS, however you can separate files or groups of files if required (see below). In production an MD5 fingerprint is inserted into each filename. +The default behavior in Rails 3.1 and onward is to concatenate all files into one master file each for JS and CSS. However, you can separate files or groups of files if required (see below). In production an MD5 fingerprint is inserted into each filename so that the file is cached by the web browser but can be invalidated if the fingerprint is altered. -The second feature of the pipeline is to minify or compress. For CSS this usually involves removing whitespace and comments. For Javascript more complex processes can be applied. - -You can choose from a set of built in options or specify your own. +The second feature is to minify or compress. For CSS, this usually involves removing whitespace and comments. For JavaScript, more complex processes can be applied. You can choose from a set of built in options or specify your own. The third feature is the ability to code these assets using another language, or language extension. These include SCSS or Sass for CSS, CoffeeScript for Javascript, and ERB for both. @@ -62,13 +60,18 @@ Rails old strategy was to append a query string to every asset linked with a bui This has several disadvantages: -1. Not all caches will cache content with a query string - -"Steve Souders recommends":http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/, "...avoiding a querystring for cacheable resources". He found that in these case 5-20% of requests will not be cached. - -2. The filename can change between nodes in multi-server environments. +
    +
  1. + Not all caches will cache content with a query string
    -The query string in Rails is based on the files mtime (mtime is the file modification time). When assets are deployed to a cluster, there is no guarantee that the timestamps will be the same, resulting in different values being used depending on which server handles the request. + "Steve Souders recommends":http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/, "...avoiding a querystring for cacheable resources". He found that in these case 5-20% of requests will not be cached. +
  2. + +
  3. + The filename can change between nodes in multi-server environments.
    + The query string in Rails is based on the files mtime (mtime is the file modification time). When assets are deployed to a cluster, there is no guarantee that the timestamps will be the same, resulting in different values being used depending on which server handles the request. +
  4. +
The other problems is that when static assets are deployed with each new release of code, the mtime of *all* these files changes, forcing all remote clients to fetch them again, even when the content of those assets has not changed. @@ -84,7 +87,7 @@ h3. How to Use the Asset Pipeline In previous versions of Rails, all assets were located in subdirectories of +public+ such as +images+, +javascripts+ and +stylesheets+. With the asset pipeline, the preferred location for these assets is now the +app/assets+ directory. Files in this directory will be served by the Sprockets middleware included in the sprockets gem. -This is not to say that assets can (or should) no longer be placed in +public+. They still can be and will be served as static files by the application or web server. You would only use +app/assets+ if you wish your files to undergo some pre-processing before they are served. +This is not to say that assets can (or should) no longer be placed in +public+; they still can be and will be served as static files by the application or web server. You would only use +app/assets+ if you wish your files to undergo some pre-processing before they are served. When a scaffold or controller is generated for the application, Rails will also generate a JavaScript file (or CoffeeScript if the +coffee-script+ gem is in the +Gemfile+) and a Cascading Style Sheet file (or SCSS if +sass-rails+ is in the +Gemfile+) file for that controller. @@ -119,7 +122,11 @@ In regular views you can access images in the +assets/images+ directory like thi <%= image_tag "rails.png" %> -Images can be organized into directories if required, and this Just Works. +Images can be organized into directories if required, and they can be accessed by specifying the directory's name in the tag: + + + <%= image_tag "icons/rails.png" %> + Providing that assets are enabled within our application (+config.assets.enabled+ in the current environment's file is not set to +false+), this file will be served by Sprockets unless a file at +public/assets/rails.png+ exists, in which case that file will be served. @@ -138,21 +145,15 @@ This will insert a correctly formatted data uri into the CSS source. h5. CSS and ERB -If you add an erb extension to a css asset: - - -application.css.erb - - -then you can use the asset_path helper in your CSS rules: +If you add an +erb+ extension to a CSS asset, making it something such as +application.css.erb+ then you can use the +asset_path+ helper in your CSS rules: .class{background-image:<%= asset_path 'image.png' %>} -This will write the path to any specified images in +/app/assets/images+ and its subdirectories. +This will write the path to the particular asset being referenced. In this example, it would make sense to have an image in one of the asset load paths, such as +app/assets/images/image.png+, which would be referenced here. If this image is already available in +public/assets+ as a fingerprinted file then that path will be referenced. -Note that the closing tag cannot be of the style '-%>'. +Note that the closing tag cannot be of the style +-%>+. h5. CSS and SCSS @@ -160,7 +161,7 @@ TODO: Sass-rails's handy +image_url+ helpers h4. Manifest Files and Directives -Sprockets uses manifest files to determine which assets to include and serve. These manifest files contain _directives_ - instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets will load the files specified, process them if necessary, concatenate them into one single file and then compress them (if +Rails.application.config.assets.compress+ is set to +true+). By serving one file rather than many, a page's load time is greatly reduced. +Sprockets uses manifest files to determine which assets to include and serve. These manifest files contain _directives_ - instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets will load the files specified, process them if necessary, concatenate them into one single file and then compress them (if +Rails.application.config.assets.compress+ is set to +true+). By serving one file rather than many, a page's load time is greatly reduced as there is not as many requests to make for each file. For example, in the default Rails application there's a +app/assets/javascripts/application.js+ file which contains the following lines: @@ -206,7 +207,7 @@ The file extensions used on an asset will determine what preprocssing will be ap When these files are requested, they will be processed by the processors provided by the +coffee-script+ and +sass-rails+ gems and then sent back to the browser as JavaScript and CSS respectively. -Additional layers of pre-processing can be requested by adding other extensions. These should be used in the order the processing should be applied. For example, a stylesheet called +app/assets/stylesheets/projects.css.scss.erb+ would first be processed as ERB, then SCSS and finally served as CSS. The same applies to a JavaScript file - +app/assets/javascripts/projects.js.coffee.erb+ would be process as ERB, CoffeeScript and served as JavaScript. +Additional layers of pre-processing can be requested by adding other extensions, where each extension will be processed in a right-to-left manner. These should be used in the order the processing should be applied. For example, a stylesheet called +app/assets/stylesheets/projects.css.scss.erb+ would first be processed as ERB, then SCSS and finally served as CSS. The same applies to a JavaScript file - +app/assets/javascripts/projects.js.coffee.erb+ would be process as ERB, CoffeeScript and served as JavaScript. Keep in mind that the order of these pre-processors is important. For example, if we called our JavaScript file +app/assets/javascripts/projects.js.erb.coffee+ then it would be processed with the CoffeeScript interpreter first, which wouldn't understand ERB and therefore we would run into problems. @@ -266,9 +267,9 @@ Rails comes bundled with a rake task to compile the manifests to files on disc. The rake task is: - + rake assets:precompile - + You can run this as part of a Capistrano deployment: @@ -284,9 +285,9 @@ TODO: Extend above task to allow for this and add task to set it up (See commits The default matcher for compiling files will include +application.js+, +application.css+ and all files that do not end in +js+ or +css+: - + [ /\w+\.(?!js|css).+/, /application.(css|js)$/ ] - + If you have other manifests or individual stylesheet and javascript files to include, you can append them to the +precompile+ array: @@ -316,8 +317,6 @@ TODO: NGINX instructions When files are precompiled Sprockets also creates "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: -TODO: NGINX instructions - TODO: Apache instructions @@ -340,7 +339,7 @@ h4. Javascript Possible options for Javascript compression are +:closure+, +:uglifier+ and +:yui+. These require the use of the +closure-compiler+, +uglifier+ or +yui-compressor+ gems respectively. -The default Gemfile includes "uglifier":https://github.com/lautis/uglifier. This gem wraps "UglifierJS":https://github.com/mishoo/UglifyJS (written for NodeJS) in Ruby. It compress your code by removing white spaces and other magical things like changing your if and else statements to ternary operators when possible. +The default Gemfile includes "uglifier":https://github.com/lautis/uglifier. This gem wraps "UglifierJS":https://github.com/mishoo/UglifyJS (written for NodeJS) in Ruby. It compress your code by removing white spaces and other magical things like changing your +if+ and +else+ statements to ternary operators where possible. The following line will invoke uglifier for Javascript compression. @@ -352,9 +351,7 @@ The +config.assets.compress+ must be set to +true+ to enable Javascript compress h4. Using your own compressor -The compressor config settings for CSS and Javascript will also take an Object. - -This object must have a +compress+ method that takes a string as the sole argument and it must return a string. +The compressor config settings for CSS and Javascript will also take any Object. This object must have a +compress+ method that takes a string as the sole argument and it must return a string. class Transformer @@ -381,7 +378,7 @@ This can be changed to something else: config.assets.prefix = "/some_other_path" -This is a handy option if you have any existing project (pre Rails 3.1) that already uses this path. +This is a handy option if you have any existing project (pre Rails 3.1) that already uses this path or you wish to use this path for a new resource. h4. X-Sendfile headers -- cgit v1.2.3 From 3e6052a430912b096056ae3d9a685b04767a4d19 Mon Sep 17 00:00:00 2001 From: JudeArasu Date: Tue, 19 Jul 2011 06:41:20 +0530 Subject: notextile tag has been placed with ascii quotes --- railties/guides/rails_guides/generator.rb | 5 +++-- railties/guides/rails_guides/textile_extensions.rb | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/guides/rails_guides/generator.rb b/railties/guides/rails_guides/generator.rb index 14d671c8f3..2219fcea66 100644 --- a/railties/guides/rails_guides/generator.rb +++ b/railties/guides/rails_guides/generator.rb @@ -227,13 +227,13 @@ module RailsGuides end code_blocks.push(< +<notextile>
 #{ERB::Util.h($2).strip}
 
- +</notextile> HTML "\ndirty_workaround_for_notextile_#{code_blocks.size - 1}\n" end @@ -280,3 +280,4 @@ HTML end end end + diff --git a/railties/guides/rails_guides/textile_extensions.rb b/railties/guides/rails_guides/textile_extensions.rb index 352c5e91dd..dd51e0d66b 100644 --- a/railties/guides/rails_guides/textile_extensions.rb +++ b/railties/guides/rails_guides/textile_extensions.rb @@ -25,7 +25,7 @@ module RailsGuides def plusplus(body) body.gsub!(/\+(.*?)\+/) do |m| - "#{$1}" + "<notextile>#{$1}</notextile>" end # The real plus sign @@ -36,8 +36,9 @@ module RailsGuides body.gsub!(%r{<(yaml|shell|ruby|erb|html|sql|plain)>(.*?)}m) do |m| es = ERB::Util.h($2) css_class = $1.in?(['erb', 'shell']) ? 'html' : $1 - %{
#{es}
} + %{<notextile>
#{es}
</notextile>} end end end end + -- cgit v1.2.3 From db655ec7a6219d7337e46a6121421b4782d3ea28 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Tue, 19 Jul 2011 12:18:23 +0530 Subject: Revert "notextile tag has been placed with ascii quotes" This reverts commit 3e6052a430912b096056ae3d9a685b04767a4d19. Reason: Code changes are not allowed in docrails (even if they are related to guides generation) --- railties/guides/rails_guides/generator.rb | 5 ++--- railties/guides/rails_guides/textile_extensions.rb | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'railties') diff --git a/railties/guides/rails_guides/generator.rb b/railties/guides/rails_guides/generator.rb index 2219fcea66..14d671c8f3 100644 --- a/railties/guides/rails_guides/generator.rb +++ b/railties/guides/rails_guides/generator.rb @@ -227,13 +227,13 @@ module RailsGuides end code_blocks.push(<
 #{ERB::Util.h($2).strip}
 
-</notextile> + HTML "\ndirty_workaround_for_notextile_#{code_blocks.size - 1}\n" end @@ -280,4 +280,3 @@ HTML end end end - diff --git a/railties/guides/rails_guides/textile_extensions.rb b/railties/guides/rails_guides/textile_extensions.rb index dd51e0d66b..352c5e91dd 100644 --- a/railties/guides/rails_guides/textile_extensions.rb +++ b/railties/guides/rails_guides/textile_extensions.rb @@ -25,7 +25,7 @@ module RailsGuides def plusplus(body) body.gsub!(/\+(.*?)\+/) do |m| - "<notextile>#{$1}</notextile>" + "#{$1}" end # The real plus sign @@ -36,9 +36,8 @@ module RailsGuides body.gsub!(%r{<(yaml|shell|ruby|erb|html|sql|plain)>(.*?)}m) do |m| es = ERB::Util.h($2) css_class = $1.in?(['erb', 'shell']) ? 'html' : $1 - %{<notextile>
#{es}
</notextile>} + %{
#{es}
} end end end end - -- cgit v1.2.3 From 0cf5160a803ffc219c064cce191dd111b361b377 Mon Sep 17 00:00:00 2001 From: Evan Machnic Date: Tue, 19 Jul 2011 13:36:50 -0400 Subject: Capitalization compliance for asset_pipeline doc --- railties/guides/source/asset_pipeline.textile | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index f3dbd108cc..5884ff7e66 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -11,7 +11,7 @@ By referring to this guide you will be able to: endprologue. -h3. What Is The Asset Pipeline? +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, SCSS and ERB. @@ -38,7 +38,7 @@ The second feature is to minify or compress. For CSS, this usually involves remo The third feature is the ability to code these assets using another language, or language extension. These include SCSS or Sass for CSS, CoffeeScript for Javascript, and ERB for both. -h4. What is fingerprinting and why should I care? +h4. What is Fingerprinting and Why Should I Care? Fingerprinting is a technique where the filenames of content that is static or infrequently updated is altered to be unique to the content contained in the file. @@ -105,7 +105,7 @@ Assets can be placed inside an application in one of three locations: +app/asset All subdirectories that exist within these three locations will be added to the search path for Sprockets (visible by calling +Rails.application.config.assets.paths+ in a console). When an asset is requested, these paths will be looked through to see if they contain an asset matching the name specified. Once an asset has been found, it's processed by Sprockets and served. -h4. Coding links to Assets +h4. Coding Links to Assets To access assets, we can use the same tags that we are generally familiar with: @@ -259,7 +259,7 @@ Sprockets also sets the +Cache-Control+ http header to +max-age=31536000+. This This behavior is controlled by the setting of +config.action_controller.perform_caching+ setting in Rails (which is +true+ for production, +false+ for everything else). This value is propagated to Sprockets during initialization for use when action_controller is not available. -h4. Precompiling assets +h4. Precompiling Assets Even though assets are served by Rack::Cache with far-future headers, in high traffic sites this may not be fast enough. @@ -320,7 +320,7 @@ When files are precompiled Sprockets also creates "Gzip":http://en.wikipedia.org TODO: Apache instructions -h3. Customizing The Pipeline +h3. Customizing the Pipeline h4. CSS Compression @@ -349,7 +349,7 @@ config.assets.js_compressor = :uglifier The +config.assets.compress+ must be set to +true+ to enable Javascript compression -h4. Using your own compressor +h4. Using Your Own Compressor The compressor config settings for CSS and Javascript will also take any Object. This object must have a +compress+ method that takes a string as the sole argument and it must return a string. @@ -368,7 +368,7 @@ config.assets.css_compressor = Transformer.new -h4. Changing the _assets_ path +h4. Changing the _assets_ Path The public path that Sprockets uses by default is +/assets+. @@ -380,7 +380,7 @@ config.assets.prefix = "/some_other_path" This is a handy option if you have any existing project (pre Rails 3.1) that already uses this path or you wish to use this path for a new resource. -h4. X-Sendfile headers +h4. X-Sendfile Headers The X-Sendfile header is a directive to the server to ignore the response from the application, and instead serve the file specified in the headers. In production Rails (via Sprockets) does not send the asset - just the location and a zero-length response - relying on the server to do work. Files are faster served by the webserver. Both Apache and nginx support this option. @@ -394,7 +394,7 @@ You should check that your server or hosting service actually supports this, oth Gotcha: If you are upgrading an existing application and intend to use this option, take care to paste this configuration option only into +production.rb+ (and not +application.rb+ ). -h3. How caching works +h3. How Caching Works Sprockets uses the default rails cache store to cache assets in dev and production. The only difference is filenames are fingerprinted and get far-future headers in production. -- cgit v1.2.3 From 09dd03095a1c93e6e9fdf87f889acc157bd2e360 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Tue, 19 Jul 2011 23:12:31 +0530 Subject: some corrections in assets pipeline guide --- railties/guides/source/asset_pipeline.textile | 69 +++++++++++++-------------- 1 file changed, 33 insertions(+), 36 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 5884ff7e66..9f80a5e96c 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -13,7 +13,7 @@ endprologue. 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, SCSS and ERB. +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, SCSS and ERB. Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets. Rails 3.1 includes the +sprockets-rails+ gem, which depends on the +sprockets+ gem, by default. @@ -22,7 +22,7 @@ By having this as a core feature of Rails, all developers can benefit from the p In new Rails 3.1 application the asset pipeline is enable by default. It can be disabled in +application.rb+ by putting this line inside the +Application+ class definition: - config.assets.enabled = false +config.assets.enabled = false It is recommended that you use the defaults for all new apps. @@ -36,7 +36,7 @@ The default behavior in Rails 3.1 and onward is to concatenate all files into on The second feature is to minify or compress. For CSS, this usually involves removing whitespace and comments. For JavaScript, more complex processes can be applied. You can choose from a set of built in options or specify your own. -The third feature is the ability to code these assets using another language, or language extension. These include SCSS or Sass for CSS, CoffeeScript for Javascript, and ERB for both. +The third feature is the ability to code these assets using another language, or language extension. These include SCSS or Sass for CSS, CoffeeScript for JavaScript, and ERB for both. h4. What is Fingerprinting and Why Should I Care? @@ -63,19 +63,17 @@ This has several disadvantages:
  1. Not all caches will cache content with a query string
    - "Steve Souders recommends":http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/, "...avoiding a querystring for cacheable resources". He found that in these case 5-20% of requests will not be cached.
  2. -
  3. - The filename can change between nodes in multi-server environments.
    - The query string in Rails is based on the files mtime (mtime is the file modification time). When assets are deployed to a cluster, there is no guarantee that the timestamps will be the same, resulting in different values being used depending on which server handles the request. + The file name can change between nodes in multi-server environments.
    + The query string in Rails is based on the modification time of the files. When assets are deployed to a cluster, there is no guarantee that the timestamps will be the same, resulting in different values being used depending on which server handles the request.
-The other problems is that when static assets are deployed with each new release of code, the mtime of *all* these files changes, forcing all remote clients to fetch them again, even when the content of those assets has not changed. +The other problem is that when static assets are deployed with each new release of code, the mtime of *all* these files changes, forcing all remote clients to fetch them again, even when the content of those assets has not changed. -Fingerprinting avoids all these problems be ensuring filenames are consistent based on the content. +Fingerprinting avoids all these problems by ensuring filenames are consistent based on the content. More reading: @@ -112,20 +110,20 @@ To access assets, we can use the same tags that we are generally familiar with: Sprockets does not add any new methods to require your assets, we still use the familiar +javascript_include_tag+ and +stylesheet_link_tag+. - <%= stylesheet_link_tag "application" %> - <%= javascript_include_tag "application" %> +<%= stylesheet_link_tag "application" %> +<%= javascript_include_tag "application" %> In regular views you can access images in the +assets/images+ directory like this: - <%= image_tag "rails.png" %> +<%= image_tag "rails.png" %> Images can be organized into directories if required, and they can be accessed by specifying the directory's name in the tag: - <%= image_tag "icons/rails.png" %> +<%= image_tag "icons/rails.png" %> Providing that assets are enabled within our application (+config.assets.enabled+ in the current environment's file is not set to +false+), this file will be served by Sprockets unless a file at +public/assets/rails.png+ exists, in which case that file will be served. @@ -134,22 +132,21 @@ Alternatively, a file with an MD5 hash after its name such as +public/assets/rai Otherwise, Sprockets will look through the available paths until it finds a file that matches the name and then will serve it, first looking in the application's assets directories and then falling back to the various engines of the application. -If you want to use a "css data uri":http://en.wikipedia.org/wiki/Data_URI_scheme - a method of embedding the image data directly into the CSS file - you can use the +asset_data_uri+ helper. - - - #logo { background: url(<%= asset_data_uri 'logo.png' %>) - +If you want to use a "css data URI":http://en.wikipedia.org/wiki/Data_URI_scheme - a method of embedding the image data directly into the CSS file - you can use the +asset_data_uri+ helper. -This will insert a correctly formatted data uri into the CSS source. + +#logo { background: url(<%= asset_data_uri 'logo.png' %>) + +This will insert a correctly formatted data URI into the CSS source. h5. CSS and ERB If you add an +erb+ extension to a CSS asset, making it something such as +application.css.erb+ then you can use the +asset_path+ helper in your CSS rules: - + .class{background-image:<%= asset_path 'image.png' %>} - + This will write the path to the particular asset being referenced. In this example, it would make sense to have an image in one of the asset load paths, such as +app/assets/images/image.png+, which would be referenced here. If this image is already available in +public/assets+ as a fingerprinted file then that path will be referenced. @@ -229,15 +226,15 @@ You can put +?debug_assets=true+ or +?debug_assets=1+ at the end of a URL and Sp By default, this would only render this line when used with +<%= javascript_include_tag "application" %>+ in a view or layout: - + When the +debug_assets+ parameter is set, this line will be expanded out into three separate lines, separating out the combined file into their parts. - - - + + + This allows the individual parts of an asset to be rendered and debugged separately. @@ -279,7 +276,7 @@ before 'deploy:symlink' do end -If you are not precompiling your assets, and you are using the default cache file store (which is the filesystem), you will need to symlink +rails_root/tmp/cache/assets+ from the shared folder that is part of the Capistrano deployment structure. This is so the cached file persist between deployments. +If you are not precompiling your assets, and you are using the default cache file store (which is the file system), you will need to symlink +rails_root/tmp/cache/assets+ from the shared folder that is part of the Capistrano deployment structure in order to persist the cached file between deployments. TODO: Extend above task to allow for this and add task to set it up (See commits 8f0e0b6 and 704ee0df). Note: Capistrano folks are working on a recipe - update this when it available (see https://github.com/capistrano/capistrano/pull/35). @@ -289,7 +286,7 @@ The default matcher for compiling files will include +application.js+, +applicat [ /\w+\.(?!js|css).+/, /application.(css|js)$/ ] -If you have other manifests or individual stylesheet and javascript files to include, you can append them to the +precompile+ array: +If you have other manifests or individual stylesheets and JavaScript files to include, you can append them to the +precompile+ array: config.assets.precompile << ['admin.js', 'admin.css', 'swfObject.js'] @@ -335,23 +332,23 @@ config.assets.css_compressor = :yui The +config.assets.compress+ must be set to +true+ to enable CSS compression -h4. Javascript +h4. JavaScript -Possible options for Javascript compression are +:closure+, +:uglifier+ and +:yui+. These require the use of the +closure-compiler+, +uglifier+ or +yui-compressor+ gems respectively. +Possible options for JavaScript compression are +:closure+, +:uglifier+ and +:yui+. These require the use of the +closure-compiler+, +uglifier+ or +yui-compressor+ gems respectively. The default Gemfile includes "uglifier":https://github.com/lautis/uglifier. This gem wraps "UglifierJS":https://github.com/mishoo/UglifyJS (written for NodeJS) in Ruby. It compress your code by removing white spaces and other magical things like changing your +if+ and +else+ statements to ternary operators where possible. -The following line will invoke uglifier for Javascript compression. +The following line will invoke uglifier for JavaScript compression. config.assets.js_compressor = :uglifier -The +config.assets.compress+ must be set to +true+ to enable Javascript compression +The +config.assets.compress+ must be set to +true+ to enable JavaScript compression h4. Using Your Own Compressor -The compressor config settings for CSS and Javascript will also take any Object. This object must have a +compress+ method that takes a string as the sole argument and it must return a string. +The compressor config settings for CSS and JavaScript will also take any Object. This object must have a +compress+ method that takes a string as the sole argument and it must return a string. class Transformer @@ -382,9 +379,9 @@ This is a handy option if you have any existing project (pre Rails 3.1) that alr h4. X-Sendfile Headers -The X-Sendfile header is a directive to the server to ignore the response from the application, and instead serve the file specified in the headers. In production Rails (via Sprockets) does not send the asset - just the location and a zero-length response - relying on the server to do work. Files are faster served by the webserver. Both Apache and nginx support this option. +The X-Sendfile header is a directive to the server to ignore the response from the application, and instead serve the file specified in the headers. In production Rails (via Sprockets) does not send the asset - just the location and a zero-length response - relying on the web server to do the file serving, which is usually faster. Both Apache and nginx support this option. -New applications contain this line in +production.rb+ +The configuration is available in config/environments/production.rb. config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx @@ -392,11 +389,11 @@ config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' You should check that your server or hosting service actually supports this, otherwise comment it out. -Gotcha: If you are upgrading an existing application and intend to use this option, take care to paste this configuration option only into +production.rb+ (and not +application.rb+ ). +WARNING: If you are upgrading an existing application and intend to use this option, take care to paste this configuration option only into +production.rb+ (and not +application.rb+) and any other environment you define with production behaviour. h3. How Caching Works -Sprockets uses the default rails cache store to cache assets in dev and production. The only difference is filenames are fingerprinted and get far-future headers in production. +Sprockets uses the default rails cache store to cache assets in dev and production. The only difference is file names are fingerprinted and get far-future headers in production. TODO: Add more about changing the default store. -- cgit v1.2.3 From 4885e5d3ebffa4a95f98dcedfeed9613308377d0 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Tue, 19 Jul 2011 23:19:40 +0530 Subject: minor corrections in form helpers guide and api docs --- railties/guides/source/form_helpers.textile | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile index e10620272b..96a52af612 100644 --- a/railties/guides/source/form_helpers.textile +++ b/railties/guides/source/form_helpers.textile @@ -177,12 +177,12 @@ Other form controls worth mentioning are the text area, password input, hidden i <%= password_field_tag(:password) %> <%= hidden_field_tag(:parent_id, "5") %> <%= search_field(:user, :name) %> -<%= telephone_field(:user, :phone) %> -<%= url_field(:user, "homepage) %> +<%= telephone_field(:user, :phone) %> +<%= url_field(:user, :homepage) %> <%= email_field(:user, :address) %> -output: +Output: @@ -194,8 +194,7 @@ output: -Hidden inputs are not shown to the user, but they hold data like any textual input. Values inside them can be changed with JavaScript. The search, tel, url and email inputs are specified in HTML5 and may receive special handling and/or formatting -in some user-agents. +Hidden inputs are not shown to the user, but they hold data like any textual input. Values inside them can be changed with JavaScript. The search, tel, url and email inputs are specified in HTML5 and may receive special handling and/or formatting in some user-agents. TIP: If you're using password input fields (for any purpose), you might want to configure your application to prevent those parameters from being logged. -- cgit v1.2.3 From 4a54e404882708ee8b691ec8de9b663954f8b683 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Tue, 19 Jul 2011 23:44:06 +0530 Subject: Fixing the incorrect change made in bae54c5 --- railties/guides/source/asset_pipeline.textile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 9f80a5e96c..8b3550b4b7 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -405,7 +405,4 @@ A good example of this is the +jquery-rails+ gem which comes with Rails as the s h3. Making Your Library or Gem a Pre-Processor -"You should be able to register [your gems] on "Tilt":Tilt and Sprockets will find them." - Josh -[Tilt]https://github.com/rtomayko/tilt - - +TODO: Registering gems on "Tilt":https://github.com/rtomayko/tilt enabling Sprockets to find them. -- cgit v1.2.3 From 46be69a220cf1815320ecdd7595d8fa37dcb5fd5 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Tue, 19 Jul 2011 23:54:48 +0530 Subject: spacing fix --- railties/lib/rails/engine.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 556aed19cf..b5b4c2becc 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -73,7 +73,7 @@ module Rails # == Paths # # Since Rails 3.0, applications and engines have more flexible path configuration (as - # opposed to the previous hardcoded path configuration). This means that you are not + # opposed to the previous hardcoded path configuration). This means that you are not # required to place your controllers at app/controllers, but in any place # which you find convenient. # -- cgit v1.2.3 From 2f4d9ef34e5c70057a9fe9e96e6b1e45d6341497 Mon Sep 17 00:00:00 2001 From: Evan Machnic Date: Tue, 19 Jul 2011 14:46:19 -0400 Subject: image_url documentation in asset_pipelin doc --- railties/guides/source/asset_pipeline.textile | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 5884ff7e66..6941eed6d2 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -157,7 +157,15 @@ Note that the closing tag cannot be of the style +-%>+. h5. CSS and SCSS -TODO: Sass-rails's handy +image_url+ helpers +When using the asset pipeline, paths to assets must be re-written and +sass-rails+ provides +_url+ and +_path+ helpers for the following asset classes: image, font, video, audio, javascript, stylesheet. + +* +image_url("rails.png")+ becomes +url(/assets/rails.png)+ +* +image_path("rails.png")+ becomes +"/assets/rails.png"+. + +The more generic form can also be used but the asset path and class must both be specified: + +* +asset_url("rails.png", image)+ becomes +url(/assets/rails.png)+ +* +asset_path("rails.png", image)+ becomes +"/assets/rails.png"+ h4. Manifest Files and Directives -- cgit v1.2.3 From 51df7cac8f3813d27439df7bb3a8b179be4de917 Mon Sep 17 00:00:00 2001 From: Evan Machnic Date: Tue, 19 Jul 2011 14:59:06 -0400 Subject: Fixed asset_url in asset_pipeline doc --- railties/guides/source/asset_pipeline.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 826daa4ab1..e4db2d7928 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -161,8 +161,8 @@ When using the asset pipeline, paths to assets must be re-written and +sass-rail The more generic form can also be used but the asset path and class must both be specified: -* +asset_url("rails.png", image)+ becomes +url(/assets/rails.png)+ -* +asset_path("rails.png", image)+ becomes +"/assets/rails.png"+ +* +asset_url("rails.png", "image")+ becomes +url(/assets/rails.png)+ +* +asset_path("rails.png", "image")+ becomes +"/assets/rails.png"+ h4. Manifest Files and Directives -- cgit v1.2.3 From e7a7591087656a4d81bada63699e3eb0b2450928 Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Thu, 21 Jul 2011 14:58:20 +0300 Subject: Fix typo --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index e4db2d7928..0d29b77b63 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -208,7 +208,7 @@ For some assets (like CSS) the compiled order is important. You can specify indi h4. Preprocessing -The file extensions used on an asset will determine what preprocssing will be applied. When a controller or a scaffold is generated with the default Rails gemset, a CoffeeScript file and a SCSS file will be generated in place of a regular JavaScript and CSS file. The example used before was a controller called "projects", which generated an +app/assets/javascripts/projects.js.coffee+ and a +app/assets/stylesheets/projects.css.scss+ file. +The file extensions used on an asset will determine what preprocessing will be applied. When a controller or a scaffold is generated with the default Rails gemset, a CoffeeScript file and a SCSS file will be generated in place of a regular JavaScript and CSS file. The example used before was a controller called "projects", which generated an +app/assets/javascripts/projects.js.coffee+ and a +app/assets/stylesheets/projects.css.scss+ file. When these files are requested, they will be processed by the processors provided by the +coffee-script+ and +sass-rails+ gems and then sent back to the browser as JavaScript and CSS respectively. -- cgit v1.2.3 From 9c7a55cf1126216eefb8b56564d4b2fc2363cb87 Mon Sep 17 00:00:00 2001 From: JudeArasu Date: Thu, 21 Jul 2011 22:57:41 +0530 Subject: typo change --- railties/guides/source/caching_with_rails.textile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile index 252003edd0..1bd409944a 100644 --- a/railties/guides/source/caching_with_rails.textile +++ b/railties/guides/source/caching_with_rails.textile @@ -15,7 +15,7 @@ h3. Basic Caching This is an introduction to the three types of caching techniques that Rails provides by default without the use of any third party plugins. -To start playing with testing you'll want to ensure that +config.action_controller.perform_caching+ is set to +true+ if you're running in development mode. This flag is normally set in the corresponding +config/environments/*.rb+ and caching is disabled by default for development and test, and enabled for production. +To start playing with caching you'll want to ensure that +config.action_controller.perform_caching+ is set to +true+ if you're running in development mode. This flag is normally set in the corresponding +config/environments/*.rb+ and caching is disabled by default for development and test, and enabled for production. config.action_controller.perform_caching = true @@ -416,3 +416,4 @@ h3. Changelog * December 27, 2008: Typo fixes * November 23, 2008: Incremental updates with various suggested changes and formatting cleanup * September 15, 2008: Initial version by Aditya Chadha + -- cgit v1.2.3 From 6dfed66c322a6812d3b89490c7a1fcdb664f9eda Mon Sep 17 00:00:00 2001 From: JudeArasu Date: Thu, 21 Jul 2011 23:52:10 +0530 Subject: grammatical changes --- railties/guides/source/caching_with_rails.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile index 1bd409944a..addfec3563 100644 --- a/railties/guides/source/caching_with_rails.textile +++ b/railties/guides/source/caching_with_rails.textile @@ -15,7 +15,7 @@ h3. Basic Caching This is an introduction to the three types of caching techniques that Rails provides by default without the use of any third party plugins. -To start playing with caching you'll want to ensure that +config.action_controller.perform_caching+ is set to +true+ if you're running in development mode. This flag is normally set in the corresponding +config/environments/*.rb+ and caching is disabled by default for development and test, and enabled for production. +To start playing with caching you'll want to ensure that +config.action_controller.perform_caching+ is set to +true+, if you're running in development mode. This flag is normally set in the corresponding +config/environments/*.rb+ and caching is disabled by default for development and test, and enabled for production. config.action_controller.perform_caching = true @@ -25,7 +25,7 @@ h4. Page Caching Page caching is a Rails mechanism which allows the request for a generated page to be fulfilled by the webserver (i.e. apache or nginx), without ever having to go through the Rails stack at all. Obviously, this is super-fast. Unfortunately, it can't be applied to every situation (such as pages that need authentication) and since the webserver is literally just serving a file from the filesystem, cache expiration is an issue that needs to be dealt with. -So, how do you enable this super-fast cache behavior? Simple, let's say you have a controller called +ProductsController+ and an +index+ action that lists all the products +So, how do you enable this super-fast cache behavior?. Simple, let's say you have a controller called +ProductsController+ and an +index+ action that lists all the products. class ProductsController < ActionController -- cgit v1.2.3 From 444e01e4af3b321e0ee3b7e4d41538dab23f7d67 Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Thu, 21 Jul 2011 23:46:42 +0530 Subject: alias added for rails runner guide --- railties/guides/source/command_line.textile | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index 9e3b25d794..a9f4931924 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -311,6 +311,8 @@ h4. +rails runner+ $ rails runner "Model.long_running_method"
+You can also use the alias "r" to run Ruby code in the context of Rails: rails r. + You can specify the environment in which the +runner+ command should operate using the +-e+ switch. -- cgit v1.2.3 From dc1b207d81313d71536a06a45237b8e98fa217ba Mon Sep 17 00:00:00 2001 From: Vishnu Atrai Date: Thu, 21 Jul 2011 23:55:31 +0530 Subject: alias added for rails generate guide --- railties/guides/source/command_line.textile | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index a9f4931924..b5e87eea3d 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -85,6 +85,8 @@ h4. +rails generate+ The +rails generate+ command uses templates to create a whole lot of things. Running +rails generate+ by itself gives a list of available generators: +You can also use the alias "g" that will work same as +rails generate+: rails g. + $ rails generate Usage: rails generate GENERATOR [args] [options] -- cgit v1.2.3 From 3cafe04c8120c1bf39dc819c6b13037f696a9c79 Mon Sep 17 00:00:00 2001 From: JudeArasu Date: Fri, 22 Jul 2011 00:28:24 +0530 Subject: grammatical changes --- railties/guides/source/caching_with_rails.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile index addfec3563..45c5aebc89 100644 --- a/railties/guides/source/caching_with_rails.textile +++ b/railties/guides/source/caching_with_rails.textile @@ -104,7 +104,7 @@ INFO: Action caching runs in an after filter. Thus, invalid requests won't gener h4. Fragment Caching -Life would be perfect if we could get away with caching the entire contents of a page or action and serving it out to the world. Unfortunately, dynamic web applications usually build pages with a variety of components not all of which have the same caching characteristics. In order to address such a dynamically created page where different parts of the page need to be cached and expired differently Rails provides a mechanism called Fragment Caching. +Life would be perfect if we could get away with caching the entire contents of a page or action and serving it out to the world. Unfortunately, dynamic web applications usually build pages with a variety of components and not all of which have the same caching characteristics. In order to address such a dynamically created page where different parts of the page need to be cached and expired differently Rails provides a mechanism called Fragment Caching. Fragment Caching allows a fragment of view logic to be wrapped in a cache block and served out of the cache store when the next request comes in. -- cgit v1.2.3 From 14b9726ecd8635254c2a174717fcfab33e5a8380 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 23 Jul 2011 01:18:28 +0530 Subject: minor corrections in caching guide --- railties/guides/source/caching_with_rails.textile | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile index 45c5aebc89..ae56911441 100644 --- a/railties/guides/source/caching_with_rails.textile +++ b/railties/guides/source/caching_with_rails.textile @@ -23,9 +23,9 @@ config.action_controller.perform_caching = true h4. Page Caching -Page caching is a Rails mechanism which allows the request for a generated page to be fulfilled by the webserver (i.e. apache or nginx), without ever having to go through the Rails stack at all. Obviously, this is super-fast. Unfortunately, it can't be applied to every situation (such as pages that need authentication) and since the webserver is literally just serving a file from the filesystem, cache expiration is an issue that needs to be dealt with. +Page caching is a Rails mechanism which allows the request for a generated page to be fulfilled by the webserver (i.e. Apache or nginx), without ever having to go through the Rails stack at all. Obviously, this is super-fast. Unfortunately, it can't be applied to every situation (such as pages that need authentication) and since the webserver is literally just serving a file from the filesystem, cache expiration is an issue that needs to be dealt with. -So, how do you enable this super-fast cache behavior?. Simple, let's say you have a controller called +ProductsController+ and an +index+ action that lists all the products. +To enable page caching, you need to use the +caches_page+ method. class ProductsController < ActionController @@ -35,11 +35,10 @@ class ProductsController < ActionController def index @products = Products.all end - end -The first time anyone requests +/products+, Rails will generate a file called +products.html+ and the webserver will then look for that file before it passes the next request for +/products+ to your Rails application. +Let's say you have a controller called +ProductsController+ and an +index+ action that lists all the products. The first time anyone requests +/products+, Rails will generate a file called +products.html+ and the webserver will then look for that file before it passes the next request for +/products+ to your Rails application. By default, the page cache directory is set to +Rails.public_path+ (which is usually set to the +public+ folder) and this can be configured by changing the configuration setting +config.action_controller.page_cache_directory+. Changing the default from +public+ helps avoid naming conflicts, since you may want to put other static html in +public+, but changing this will require web server reconfiguration to let the web server know where to serve the cached files from. @@ -104,7 +103,7 @@ INFO: Action caching runs in an after filter. Thus, invalid requests won't gener h4. Fragment Caching -Life would be perfect if we could get away with caching the entire contents of a page or action and serving it out to the world. Unfortunately, dynamic web applications usually build pages with a variety of components and not all of which have the same caching characteristics. In order to address such a dynamically created page where different parts of the page need to be cached and expired differently Rails provides a mechanism called Fragment Caching. +Life would be perfect if we could get away with caching the entire contents of a page or action and serving it out to the world. Unfortunately, dynamic web applications usually build pages with a variety of components not all of which have the same caching characteristics. In order to address such a dynamically created page where different parts of the page need to be cached and expired differently, Rails provides a mechanism called Fragment Caching. Fragment Caching allows a fragment of view logic to be wrapped in a cache block and served out of the cache store when the next request comes in. -- cgit v1.2.3 From ccb3af468328270b38e4a31ee0e353fd1d7ec327 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 23 Jul 2011 01:19:24 +0530 Subject: corrected sentences to make them consistent in command line guide --- railties/guides/source/command_line.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/command_line.textile b/railties/guides/source/command_line.textile index b5e87eea3d..b34506d4d8 100644 --- a/railties/guides/source/command_line.textile +++ b/railties/guides/source/command_line.textile @@ -85,7 +85,7 @@ h4. +rails generate+ The +rails generate+ command uses templates to create a whole lot of things. Running +rails generate+ by itself gives a list of available generators: -You can also use the alias "g" that will work same as +rails generate+: rails g. +You can also use the alias "g" to invoke the generator command: rails g. $ rails generate @@ -313,7 +313,7 @@ h4. +rails runner+ $ rails runner "Model.long_running_method" -You can also use the alias "r" to run Ruby code in the context of Rails: rails r. +You can also use the alias "r" to invoke the runner: rails r. You can specify the environment in which the +runner+ command should operate using the +-e+ switch. -- cgit v1.2.3 From 573c6e6982224e6817174d2f9c288b6ddc938608 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 23 Jul 2011 01:59:46 +0530 Subject: document the change in edge rails which makes a more strict check on the arity of the dynamic finders --- railties/guides/source/active_record_querying.textile | 1 + 1 file changed, 1 insertion(+) (limited to 'railties') diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 082f9eda7d..8ea06d28aa 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -1016,6 +1016,7 @@ You can specify an exclamation point (!) on the end of the dynamic find If you want to find both by name and locked, you can chain these finders together by simply typing +and+ between the fields. For example, +Client.find_by_first_name_and_locked("Ryan", true)+. +WARNING: Up to and including Rails 3.1, when the number of arguments passed to a dynamic finder method is lesser than the number of fields, say Client.find_by_name_and_locked("Ryan"), the behavior is to pass +nil+ as the missing argument. This is *unintentional* and this behavior will be changed in Rails 3.2 to throw an +ArgumentError+. There's another set of dynamic finders that let you find or create/initialize objects if they aren't found. These work in a similar fashion to the other finders and can be used like +find_or_create_by_first_name(params[:first_name])+. Using this will first perform a find and then create if the find returns +nil+. The SQL looks like this for +Client.find_or_create_by_first_name("Ryan")+: -- cgit v1.2.3 From 2db9a7e930f44aeeda175458a475911c2fa33f40 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 23 Jul 2011 02:21:05 +0530 Subject: minor refactor in the template guide --- railties/guides/source/rails_application_templates.textile | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/rails_application_templates.textile b/railties/guides/source/rails_application_templates.textile index 3db47a70e8..90fc763349 100644 --- a/railties/guides/source/rails_application_templates.textile +++ b/railties/guides/source/rails_application_templates.textile @@ -11,22 +11,18 @@ endprologue. h3. Usage -To apply a template, you need to provide the Rails generator with the location of the template you wish to apply, using -m option: +To apply a template, you need to provide the Rails generator with the location of the template you wish to apply, using -m option. This can either be path to a file or a URL. $ rails new blog -m ~/template.rb +$ rails new blog -m http://example.com/template.rb -It's also possible to apply a template using a URL: - - -$ rails new blog -m https://gist.github.com/755496.txt - - -Alternatively, you can use the rake task +rails:template+ to apply a template to an existing Rails application: +You can use the rake task +rails:template+ to apply templates to an existing Rails application. The location of the template needs to be passed in to an environment variable named LOCATION. Again, this can either be path to a file or a URL. $ rake rails:template LOCATION=~/template.rb +$ rake rails:template LOCATION=http://example.com/template.rb h3. Template API -- cgit v1.2.3 From 38310ab1a6f559860e25b0e28bef9560bb452ae6 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 23 Jul 2011 12:14:10 +0200 Subject: little details seen while doing a pass through what's new in docrails --- railties/guides/source/asset_pipeline.textile | 8 ++++---- railties/lib/rails/engine.rb | 3 ++- railties/lib/rails/paths.rb | 16 ++++++++-------- 3 files changed, 14 insertions(+), 13 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 0d29b77b63..5999c78369 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -42,7 +42,7 @@ h4. What is Fingerprinting and Why Should I Care? Fingerprinting is a technique where the filenames of content that is static or infrequently updated is altered to be unique to the content contained in the file. -When a filename is unique and based on its content, http headers can be set to encourage caches everywhere (at ISPs, in browsers) to keep their own copy of the content. When the content is updated, the fingerprint will change and the remote clients will request the new file. This is generally known as _cachebusting_. +When a filename is unique and based on its content, HTTP headers can be set to encourage caches everywhere (at ISPs, in browsers) to keep their own copy of the content. When the content is updated, the fingerprint will change and the remote clients will request the new file. This is generally known as _cachebusting_. The most effective technique is to insert a hash of the content into the name, usually at the end. For example a CSS file +global.css+ is hashed and the filename is updated to incorporate the hash. @@ -218,7 +218,7 @@ Keep in mind that the order of these pre-processors is important. For example, i h3. In Development -In the development environment assets are compiled and cached on the first request after the server is started. Sprockets sets a +must-validate+ cache-control http header to reduce request overhead on subsequent requests - on these the browser gets a 304 (not-modified) response. +In the development environment assets are compiled and cached on the first request after the server is started. Sprockets sets a +must-validate+ Cache-Control HTTP header to reduce request overhead on subsequent requests - on these the browser gets a 304 (not-modified) response. If any of the files in the manifest have changed between requests, the server will respond with a new compiled file. @@ -258,9 +258,9 @@ On the first request the assets are compiled and cached as described above, howe /assets/application-4dd5b109ee3439da54f5bdfd78a80473.css -The MD5 is generated from the contents of the compiled files, and is included in the http +Content-MD5+ header. +The MD5 is generated from the contents of the compiled files, and is included in the HTTP +Content-MD5+ header. -Sprockets also sets the +Cache-Control+ http header to +max-age=31536000+. This signals all caches between your server and the client browser that this content (the file served) can be cached for 1 year. The effect of this is to reduce the number of requests for this asset from your server; the asset has a good chance of being in the local browser cache or some intermediate cache. +Sprockets also sets the +Cache-Control+ HTTP header to +max-age=31536000+. This signals all caches between your server and the client browser that this content (the file served) can be cached for 1 year. The effect of this is to reduce the number of requests for this asset from your server; the asset has a good chance of being in the local browser cache or some intermediate cache. This behavior is controlled by the setting of +config.action_controller.perform_caching+ setting in Rails (which is +true+ for production, +false+ for everything else). This value is propagated to Sprockets during initialization for use when action_controller is not available. diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index b5b4c2becc..cb897e94d7 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -5,7 +5,7 @@ require 'rbconfig' require 'rails/engine/railties' module Rails - # Rails::Engine allows you to wrap a specific Rails application or subset of + # Rails::Engine allows you to wrap a specific Rails application or subset of # functionality and share it with other applications. Since Rails 3.0, every # Rails::Application is just an engine, which allows for simple # feature and application sharing. @@ -176,6 +176,7 @@ module Rails # == Engine name # # There are some places where an Engine's name is used: + # # * routes: when you mount an Engine with mount(MyEngine::Engine => '/my_engine'), # it's used as default :as option # * some of the rake tasks are based on engine name, e.g. my_engine:install:migrations, diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index 6aecebe273..daa1bdfc29 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -2,7 +2,7 @@ require 'set' module Rails module Paths - # This object is an extended hash that behaves as root of the Rails::Paths system. + # This object is an extended hash that behaves as root of the Rails::Paths system. # It allows you to collect information about how you want to structure your application # paths by a Hash like API. It requires you to give a physical path on initialization. # @@ -10,13 +10,13 @@ module Rails # root.add "app/controllers", :eager_load => true # # The command above creates a new root object and add "app/controllers" as a path. - # This means we can get a Path object back like below: + # This means we can get a +Rails::Paths::Path+ object back like below: # # path = root["app/controllers"] # path.eager_load? # => true # path.is_a?(Rails::Paths::Path) # => true # - # The Path object is simply an array and allows you to easily add extra paths: + # The +Path+ object is simply an array and allows you to easily add extra paths: # # path.is_a?(Array) # => true # path.inspect # => ["app/controllers"] @@ -24,17 +24,17 @@ module Rails # path << "lib/controllers" # path.inspect # => ["app/controllers", "lib/controllers"] # - # Notice that when you add a path using #add, the path object created already - # contains the path with the same path value given to #add. In some situations, + # Notice that when you add a path using +add+, the path object created already + # contains the path with the same path value given to +add+. In some situations, # you may not want this behavior, so you can give :with as option. # # root.add "config/routes", :with => "config/routes.rb" # root["config/routes"].inspect # => ["config/routes.rb"] # - # The #add method accepts the following options as arguments: + # The +add+ method accepts the following options as arguments: # eager_load, autoload, autoload_once and glob. # - # Finally, the Path object also provides a few helpers: + # Finally, the +Path+ object also provides a few helpers: # # root = Root.new "/rails" # root.add "app/controllers" @@ -42,7 +42,7 @@ module Rails # root["app/controllers"].expanded # => ["/rails/app/controllers"] # root["app/controllers"].existent # => ["/rails/app/controllers"] # - # Check the Path documentation for more information. + # Check the Rails::Paths::Path documentation for more information. class Root < ::Hash attr_accessor :path -- cgit v1.2.3