From d746aea6f9fd7d58358618491f45fe7406bc5a92 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sat, 18 Jun 2011 21:09:15 +1000 Subject: File needs to be at public/assets, not public/images --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 1b444811a2..23c849c1f7 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -49,7 +49,7 @@ To serve assets, we can use the same tags that we are generally familiar with: <%= image_tag "rails.png" %> -Providing that assets are enabled within our application (+Rails.application.config.assets.enabled+ is set to +true+), this file will be served by Sprockets unless a file at +public/images/rails.png+ exists, in which case that file will be served. If there is no file at +public/images+, 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. +Providing that assets are enabled within our application (+Rails.application.config.assets.enabled+ is set to +true+), this file will be served by Sprockets unless a file at +public/assets/rails.png+ exists, in which case that file will be served. If there is no file at +public/assets+, 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. To include a JavaScript file we can still use the familiar +javascript_include_tag+. -- cgit v1.2.3 From 4f301b25402fb8736921752ceba5ba79c37bfd12 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Sat, 18 Jun 2011 21:11:15 +1000 Subject: Fix indentation on manifest examples in assets guide --- railties/guides/source/asset_pipeline.textile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 23c849c1f7..febf8163f1 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -72,9 +72,9 @@ Sprockets allows some assets to be manifest files. These manifest files require For example, in the default Rails application there's a +app/assets/javascripts/application.js+ file which contains the following lines: - //= require jquery - //= require jquery_ujs - //= require_tree . +//= require jquery +//= require jquery_ujs +//= require_tree . In JS files, directives begin with +//=+. In this case, the file is using the +require+ directive twice and the +require_tree+ directive once. The +require+ directive tells Sprockets that we would like to require a file called +jquery.js+ that is available somewhere in the search path for Sprockets. By default, this is located inside the +vendor/assets/javascripts+ directory contained within the +jquery_rails+ gem. An identical event takes place for the +jquery_ujs+ require specified here also. @@ -84,10 +84,10 @@ The +require_tree .+ directive tells Sprockets to include _all_ JavaScript files There's also a default +app/assets/stylesheets/application.css+ file which contains these lines: - /* ... - *= require_self - *= require_tree . - */ +/* ... +*= require_self +*= require_tree . +*/ The directives that work in the JavaScript files will also work in stylesheets, obviously requiring stylesheets rather than JavaScript files. The +require_tree+ directive here works the same way as the JavaScript one, requiring all stylesheets from the current directory. -- cgit v1.2.3 From fb9bfc2430924bced50f4cc285374bfdeb83f685 Mon Sep 17 00:00:00 2001 From: Leonard Garvey Date: Sat, 18 Jun 2011 21:15:49 +1000 Subject: Fixed a typo in asset pipeline --- railties/guides/source/asset_pipeline.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 1b444811a2..5af3dff41a 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -98,7 +98,7 @@ h4. Preprocessing Based on the extensions of the assets, Sprockets will do preprocessing on the files. With the default gemset that comes with Rails, when a controller or a scaffold is generated, 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 SCSS respectively. +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. In addition to this single layer of pre-processing, we can also put on additional extensions to the end of the file in order for them to be processed using other languages first. For example, we could call our stylesheet +app/assets/stylesheets/projects.css.scss.erb+ it would first be processed as ERB, then SCSS and finally served as CSS. We could also do this with our JavaScript file, calling it +app/assets/javascripts/projects.js.coffee.erb+. @@ -106,4 +106,4 @@ Keep in mind that the order of these pre-processors is important. For example, i h4. Compressing Assets -WIP: Compressed Assets in Rails are served ... how? \ No newline at end of file +WIP: Compressed Assets in Rails are served ... how? -- cgit v1.2.3 From 0a45e24879a604924fea4cced7528fd98d1c3c35 Mon Sep 17 00:00:00 2001 From: Scott Stewart Date: Sat, 18 Jun 2011 06:31:22 -0700 Subject: Edited railties/guides/source/asset_pipeline.textile via GitHub --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index a795b88ef5..fdfac8a9d9 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -77,7 +77,7 @@ For example, in the default Rails application there's a +app/assets/javascripts/ //= require_tree . -In JS files, directives begin with +//=+. In this case, the file is using the +require+ directive twice and the +require_tree+ directive once. The +require+ directive tells Sprockets that we would like to require a file called +jquery.js+ that is available somewhere in the search path for Sprockets. By default, this is located inside the +vendor/assets/javascripts+ directory contained within the +jquery_rails+ gem. An identical event takes place for the +jquery_ujs+ require specified here also. +In JS files, directives begin with +//=+. In this case, the file is using the +require+ directive twice and the +require_tree+ directive once. The +require+ directive tells Sprockets that we would like to require a file called +jquery.js+ that is available somewhere in the search path for Sprockets. By default, this is located inside the +vendor/assets/javascripts+ directory contained within the +jquery-rails+ gem. An identical event takes place for the +jquery_ujs+ require specified here also. The +require_tree .+ directive tells Sprockets to include _all_ JavaScript files in this directory into the output. A path relative to the file can be specified if only certain files are required to be loaded. -- cgit v1.2.3 From a637e1dcb1d954e32c7681dfdfd5a86adfdb5057 Mon Sep 17 00:00:00 2001 From: Scott Stewart Date: Sat, 18 Jun 2011 06:40:27 -0700 Subject: Fixed typo in asset_pipeline, jquery_rails should be jquery-rails --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index fdfac8a9d9..4330e0a365 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -39,7 +39,7 @@ Any subdirectory that exists within these three locations will be added to the s h4. External Assets -Assets can also come from external sources such as engines. A good example of this is the +jquery_rails+ gem which comes with Rails 3.1 as standard. This gem contains an engine class which inherits from +Rails::Engine+. By doing this, Rails is informed that the directory for this gem may contain assets and the +app/assets+, +lib/assets+ and +vendor/assets+ directories of this engine are added to the search path of Sprockets. +Assets can also come from external sources such as engines. A good example of this is the +jquery-rails+ gem which comes with Rails 3.1 as standard. This gem contains an engine class which inherits from +Rails::Engine+. By doing this, Rails is informed that the directory for this gem may contain assets and the +app/assets+, +lib/assets+ and +vendor/assets+ directories of this engine are added to the search path of Sprockets. h4. Serving Assets -- cgit v1.2.3 From 4a36817b5d437b6d78563a298b2634c05803a0c6 Mon Sep 17 00:00:00 2001 From: Mohammad Typaldos Date: Sat, 18 Jun 2011 08:58:38 -0700 Subject: Edited railties/guides/source/asset_pipeline.textile via GitHub --- railties/guides/source/asset_pipeline.textile | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 4330e0a365..5e75dd3578 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -49,21 +49,9 @@ To serve assets, we can use the same tags that we are generally familiar with: <%= image_tag "rails.png" %> -Providing that assets are enabled within our application (+Rails.application.config.assets.enabled+ is set to +true+), this file will be served by Sprockets unless a file at +public/assets/rails.png+ exists, in which case that file will be served. If there is no file at +public/assets+, 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. +Providing that assets are enabled within our application (+config.assets.enabled+ in your environment is set to +true+), this file will be served by Sprockets unless a file at +public/assets/rails.png+ exists, in which case that file will be served. 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. -To include a JavaScript file we can still use the familiar +javascript_include_tag+. - - - <%= javascript_include_tag "application" %> - - -Similarly, to include a CSS file we can also still use +stylesheet_link_tag+. - - - <%= stylesheet_link_tag "application" %> - - -These files could just be straight JavaScript or CSS files, or they could be _manifest files_. +Sprockets does not add any new methods to require your assets, we still use the familiar +javascript_include_tag+ and +stylesheet_link_tag+. You can use it to include from the normal public directory or the assets directory. h4. Manifest Files and Directives @@ -77,9 +65,9 @@ For example, in the default Rails application there's a +app/assets/javascripts/ //= require_tree . -In JS files, directives begin with +//=+. In this case, the file is using the +require+ directive twice and the +require_tree+ directive once. The +require+ directive tells Sprockets that we would like to require a file called +jquery.js+ that is available somewhere in the search path for Sprockets. By default, this is located inside the +vendor/assets/javascripts+ directory contained within the +jquery-rails+ gem. An identical event takes place for the +jquery_ujs+ require specified here also. +In JavaScript files, directives begin with +//=+. In this case, the following file is using the +require+ directive and the +require_tree+ directive. The +require+ directive tells Sprockets that we would like to require a file called +jquery.js+ that is available somewhere in the search path for Sprockets. By default, this is located inside the +vendor/assets/javascripts+ directory contained within the +jquery-rails+ gem. An identical event takes place for the +jquery_ujs+ require specified here also. -The +require_tree .+ directive tells Sprockets to include _all_ JavaScript files in this directory into the output. A path relative to the file can be specified if only certain files are required to be loaded. +The +require_tree .+ directive tells Sprockets to include _all_ JavaScript files in this directory into the output. Only a path relative to the file can be specified. There's also a default +app/assets/stylesheets/application.css+ file which contains these lines: @@ -107,3 +95,7 @@ Keep in mind that the order of these pre-processors is important. For example, i h4. Compressing Assets WIP: Compressed Assets in Rails are served ... how? + +h4. Adding Assets to Your Gems + +h4. Making Your Library or Gem a Pre-Processors -- cgit v1.2.3 From 618802df714efa64a9f8a399afbd3ad07f914212 Mon Sep 17 00:00:00 2001 From: Mohammad Typaldos Date: Sat, 18 Jun 2011 09:00:13 -0700 Subject: Sprockets itself doesn't do this, it's uglifier and other gems, Sprockets is just the puppet master. --- railties/guides/source/asset_pipeline.textile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 5e75dd3578..a3aee01b4a 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -13,9 +13,7 @@ endprologue. h3. What Is The Asset Pipeline? -With Rails 3.1 comes a new feature known as the asset pipeline. The asset pipeline provides features that have usually been implemented by external gems, such as Jammit and Sprockets. These gems would serve concatenated or compressed versions of the assets of an application, such as stylesheets or javascript files so that the number of requests made to the server are lessened, making the page load faster. - -By having this now as a core feature of Rails, all developers can benefit from the power of having their assets pre-processed, compressed and minified by one central gem, Sprockets. +With Rails 3.1 comes a new feature known as the asset pipeline. The asset pipeline provides features that have usually been implemented by external gems, such as Jammit and Sprockets. These gems would serve concatenated or compressed versions of the assets of an application, such as stylesheets or javascript files so that the number of requests made to the server are lessened, making the page load faster. Rails 3.1 now includes the later gem, Sprockets. h3. How to Use the Asset Pipeline -- cgit v1.2.3 From 52252271105d02cfa46634e974f2fcfa5ddc84e1 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 18 Jun 2011 22:19:32 +0530 Subject: edit assets guide for cases & minor wording changes --- railties/guides/source/asset_pipeline.textile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index a3aee01b4a..2a3a172118 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? -With Rails 3.1 comes a new feature known as the asset pipeline. The asset pipeline provides features that have usually been implemented by external gems, such as Jammit and Sprockets. These gems would serve concatenated or compressed versions of the assets of an application, such as stylesheets or javascript files so that the number of requests made to the server are lessened, making the page load faster. Rails 3.1 now includes the later gem, Sprockets. +With Rails 3.1 comes a new feature known as the asset pipeline. The asset pipeline provides features that have usually been implemented by external gems, such as Jammit and Sprockets. These gems would serve concatenated or compressed versions of the assets of an application, such as stylesheets or JavaScript files so that the number of requests made to the server are reduced, making the page load faster. Rails 3.1 includes the Sprockets gem. h3. How to Use the Asset Pipeline @@ -27,7 +27,7 @@ h4. Asset Organization Assets can be placed inside an application in one of three locations: +app/assets+, +lib/assets+ or +vendor/assets+. -+app/assets+ is for assets that are owned by the application, such as custom images, javascript files or stylesheets. ++app/assets+ is for assets that are owned by the application, such as custom images, JavaScript files or stylesheets. +lib/assets+ is for your own libraries' code that doesn't really fit into the scope of the application or those libraries which are shared across applications. @@ -96,4 +96,4 @@ WIP: Compressed Assets in Rails are served ... how? h4. Adding Assets to Your Gems -h4. Making Your Library or Gem a Pre-Processors +h4. Making Your Library or Gem a Pre-Processor -- cgit v1.2.3 From 8bb7c863966695ef0b0bdfb7868394c20beeace4 Mon Sep 17 00:00:00 2001 From: Mohammad Typaldos Date: Sat, 18 Jun 2011 11:48:00 -0700 Subject: Let the reader know what JS and CSS stand for. Slight rewording as well. --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 2a3a172118..eca38d8543 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -21,7 +21,7 @@ In previous versions of Rails, all assets lived under the +public+ directory in This is not to say that assets can (or should) no longer be placed in +public+. They still can be, they will just be served by the application or the web server which is running the application and served just like normal files. 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 (or CoffeeScript if the +coffee-script+ gem is in the +Gemfile+) and CSS (or SCSS if +sass-rails+ is in the +Gemfile+) file for that controller. For example, if a +ProjectsController+ is generated, there will be a new file at +app/assets/javascripts/projects.js.coffee+ and another at +app/assets/stylesheets/projects.css.scss+. It's in these files that JavaScript and CSS unique to this part of the application belong. +When a scaffold or controller is generated for the application, Rails will also generate a JavaScript (JS) file (or CoffeeScript if the +coffee-script+ gem is in the +Gemfile+) and a Cascade Style Sheet (CSS) file (or SCSS if +sass-rails+ is in the +Gemfile+) file for that controller. For example, if a +ProjectsController+ is generated, there will be a new file at +app/assets/javascripts/projects.js.coffee+ and another at +app/assets/stylesheets/projects.css.scss+. You should put any JavaScript or CSS unique to the controller insider their respective asset files. h4. Asset Organization -- cgit v1.2.3 From 04daede85d9857e88a0e89019ec6a8ef136330b4 Mon Sep 17 00:00:00 2001 From: Mohammad Typaldos Date: Sat, 18 Jun 2011 11:57:15 -0700 Subject: Edited railties/guides/source/asset_pipeline.textile via GitHub --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index eca38d8543..2c1646d486 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -21,7 +21,7 @@ In previous versions of Rails, all assets lived under the +public+ directory in This is not to say that assets can (or should) no longer be placed in +public+. They still can be, they will just be served by the application or the web server which is running the application and served just like normal files. 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 (JS) file (or CoffeeScript if the +coffee-script+ gem is in the +Gemfile+) and a Cascade Style Sheet (CSS) file (or SCSS if +sass-rails+ is in the +Gemfile+) file for that controller. For example, if a +ProjectsController+ is generated, there will be a new file at +app/assets/javascripts/projects.js.coffee+ and another at +app/assets/stylesheets/projects.css.scss+. You should put any JavaScript or CSS unique to the controller insider their respective asset files. +When a scaffold or controller is generated for the application, Rails will also generate a JavaScript (JS) file (or CoffeeScript if the +coffee-script+ gem is in the +Gemfile+) and a Cascade Style Sheet (CSS) file (or SCSS if +sass-rails+ is in the +Gemfile+) file for that controller. For example, if a +ProjectsController+ is generated, there will be a new file at +app/assets/javascripts/projects.js.coffee+ and another at +app/assets/stylesheets/projects.css.scss+. You should put any JavaScript or CSS unique to a controller inside their respective asset files. h4. Asset Organization -- cgit v1.2.3 From 8d64aafa98c0806f34be02c0b38bb4bd9fca2ed9 Mon Sep 17 00:00:00 2001 From: Mohammad Typaldos Date: Sat, 18 Jun 2011 15:13:41 -0700 Subject: Consistency issues with pre-processor --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 2c1646d486..0dfa4be292 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -6,7 +6,7 @@ By referring to this guide you will be able to: * Understand what the asset pipeline is and what it does * Properly organize your application assets * Understand the benefits of the asset pipeline -* Adding a preprocessor to the pipeline +* Adding a pre-processor to the pipeline * Package assets with a gem endprologue. -- cgit v1.2.3 From 427b07baa16ac4f61e0762e52e716fe9937b498a Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Mon, 20 Jun 2011 00:36:52 +0530 Subject: document the instance_reader option for class_attribute --- .../source/active_support_core_extensions.textile | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 221d20fee6..7f33cc4df5 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -947,7 +947,7 @@ h4. Class Attributes h5. +class_attribute+ -The method +class_attribute+ declares one or more inheritable class attributes that can be overridden at any level down the hierarchy: +The method +class_attribute+ declares one or more inheritable class attributes that can be overridden at any level down the hierarchy. class A @@ -983,7 +983,7 @@ self.default_params = { }.freeze -They can be also accessed and overridden at the instance level: +They can be also accessed and overridden at the instance level. A.x = 1 @@ -996,7 +996,7 @@ a1.x # => 1, comes from A a2.x # => 2, overridden in a2 -The generation of the writer instance method can be prevented by setting the option +:instance_writer+ to false, as in +The generation of the writer instance method can be prevented by setting the option +:instance_writer+ to +false+. module ActiveRecord @@ -1009,8 +1009,20 @@ end A model may find that option useful as a way to prevent mass-assignment from setting the attribute. +The generation of the reader instance method can be prevented by setting the option +:instance_reader+ to +false+. + + +class A + class_attribute :x, :instance_reader => false +end + +A.x = 1 # NoMethodError + + For convenience +class_attribute+ also defines an instance predicate which is the double negation of what the instance reader returns. In the examples above it would be called +x?+. +When +:instance_reader+ is +false+, the instance predicate returns a +NoMethodError+ just like the reader method. + NOTE: Defined in +active_support/core_ext/class/attribute.rb+ h5. +cattr_reader+, +cattr_writer+, and +cattr_accessor+ -- cgit v1.2.3 From d1b448ed3fe973957eef76c050278b0247db4764 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Mon, 20 Jun 2011 01:24:04 +0530 Subject: minor changes in getting started guide --- railties/guides/source/getting_started.textile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 3011f7136b..cab6c98304 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -5,7 +5,7 @@ This guide covers getting up and running with Ruby on Rails. After reading it, y * Installing Rails, creating a new Rails application, and connecting your application to a database * The general layout of a Rails application * The basic principles of MVC (Model, View Controller) and RESTful design -* How to quickly generate the starting pieces of a Rails application. +* How to quickly generate the starting pieces of a Rails application endprologue. @@ -205,8 +205,8 @@ h4. Configuring a Database Just about every Rails application will interact with a database. The database to use is specified in a configuration file, +config/database.yml+. If you open this file in a new Rails application, you'll see a default database configuration using SQLite3. The file contains sections for three different environments in which Rails can run by default: -* The +development+ environment is used on your development computer as you interact manually with the application -* The +test+ environment is used to run automated tests +* The +development+ environment is used on your development computer as you interact manually with the application. +* The +test+ environment is used to run automated tests. * The +production+ environment is used when you deploy your application for the world to use. h5. Configuring an SQLite3 Database @@ -448,10 +448,10 @@ h4. Adding a Link To hook the posts up to the home page you've already created, you can add a link to the home page. Open +app/views/home/index.html.erb+ and modify it as follows: - +

Hello, Rails!

<%= link_to "My Blog", posts_path %> -
+
The +link_to+ method is one of Rails' built-in view helpers. It creates a hyperlink based on text to display and where to go - in this case, to the path for posts. -- cgit v1.2.3 From 9513474e5e41458e641fb38176b956c2b80b9a0a Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Mon, 20 Jun 2011 01:42:43 +0530 Subject: AR: use where in place of find --- railties/guides/source/association_basics.textile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile index 458bfefad8..3c2497e83a 100644 --- a/railties/guides/source/association_basics.textile +++ b/railties/guides/source/association_basics.textile @@ -1120,11 +1120,9 @@ h6(#has_many-collection-find). collection.find(...) The collection.find method finds objects within the collection. It uses the same syntax and options as +ActiveRecord::Base.find+. -@open_orders = @customer.orders.all(:conditions => "open = 1") +@open_orders = @customer.orders.where(:open => 1) -NOTE: Starting Rails 3, supplying options to +ActiveRecord::Base.find+ method is discouraged. Use collection.where instead when you need to pass conditions. - h6(#has_many-collection-where). collection.where(...) The collection.where method finds objects within the collection based on the conditions supplied but the objects are loaded lazily meaning that the database is queried only when the object(s) are accessed. -- cgit v1.2.3 From 5eac40bb7508947f181d8eb6bdff547ec3b4ef36 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Mon, 20 Jun 2011 02:12:21 +0530 Subject: document Active Record's reverse_order method --- .../guides/source/active_record_querying.textile | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'railties/guides/source') diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index b4ce60fcaa..e3871a3c34 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -57,6 +57,7 @@ The methods are: * +group+ * +order+ * +reorder+ +* +reverse_order+ * +limit+ * +offset+ * +joins+ @@ -550,6 +551,32 @@ In case the +reorder+ clause is not used, the SQL executed would be: SELECT * FROM posts WHERE id = 10 ORDER BY posted_at DESC +h4. +reverse_order+ + +The +reverse_order+ method reverses the ordering clause if specified. + + +Client.where("orders_count > 10").order(:name).reverse_order + + +The SQL that would be executed: + +SELECT * FROM clients WHERE orders_count > 10 ORDER BY name DESC + + +If no ordering clause is specified in the query, the +reverse_order+ orders by the primary key in reverse order. + + +Client.where("orders_count > 10").reverse_order + + +The SQL that would be executed: + +SELECT * FROM clients WHERE orders_count > 10 ORDER BY clients.id DESC + + +This method accepts *no* arguments. + h3. Readonly Objects Active Record provides +readonly+ method on a relation to explicitly disallow modification or deletion of any of the returned object. Any attempt to alter or destroy a readonly record will not succeed, raising an +ActiveRecord::ReadOnlyRecord+ exception. -- cgit v1.2.3 From d3b7f4912ba9df0297d36068e7021c795d9b1ec0 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Mon, 20 Jun 2011 15:24:41 +0530 Subject: Closing --- railties/guides/source/getting_started.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index cab6c98304..6aca5d3420 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -289,7 +289,7 @@ development: database: blog_development username: blog password: - + Change the username and password in the +development+ section as appropriate. -- cgit v1.2.3 From 2d4d9f1937af42d76bd7ebb5297d9b2564067c37 Mon Sep 17 00:00:00 2001 From: Mohammad Typaldos Date: Mon, 20 Jun 2011 23:23:55 -0700 Subject: Edited railties/guides/source/asset_pipeline.textile via GitHub --- railties/guides/source/asset_pipeline.textile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 0dfa4be292..815d4e096d 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -92,8 +92,13 @@ Keep in mind that the order of these pre-processors is important. For example, i h4. Compressing Assets -WIP: Compressed Assets in Rails are served ... how? +The default Gemfile also includes the "uglifier":https://github.com/lautis/uglifier gem. 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. h4. Adding Assets to Your Gems +To include your assets inside of a gem, simple package it in +lib/assets+ as you would in +app/assets+. You should append or prepend the name of your gem though, this should help avoid name conflicts with other gems or the user's application. + h4. 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 \ No newline at end of file -- cgit v1.2.3 From fcebf9fd93ed1dc9369f65ad91170d34653df404 Mon Sep 17 00:00:00 2001 From: Mohammad Typaldos Date: Mon, 20 Jun 2011 23:29:39 -0700 Subject: Sprockets itself doesn't compress --- railties/guides/source/asset_pipeline.textile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 815d4e096d..d0c1faa80d 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -13,15 +13,15 @@ endprologue. h3. What Is The Asset Pipeline? -With Rails 3.1 comes a new feature known as the asset pipeline. The asset pipeline provides features that have usually been implemented by external gems, such as Jammit and Sprockets. These gems would serve concatenated or compressed versions of the assets of an application, such as stylesheets or JavaScript files so that the number of requests made to the server are reduced, making the page load faster. Rails 3.1 includes the Sprockets gem. +With Rails 3.1 comes a new feature known as the asset pipeline. The asset pipeline provides features that have usually been implemented by external gems, such as "Jammit":http://documentcloud.github.com/jammit and "Sprockets.":http://getsprockets.org These gems are popular for being able to serve concatenated or compressed versions of the assets of an application, such as Cascade Style Sheets (CSS) or JavaScript (JS) files so that the number of requests made to the server are reduced, making the page load faster. Rails 3.1 includes the Sprockets gem. h3. How to Use the Asset Pipeline -In previous versions of Rails, all assets lived under the +public+ directory in directories such as +images+, +javascripts+ and +stylesheets+. With Rails 3.1, 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. +In previous versions of Rails, all assets lived under the +public+ directory in directories 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, they will just be served by the application or the web server which is running the application and served just like normal files. 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 (JS) file (or CoffeeScript if the +coffee-script+ gem is in the +Gemfile+) and a Cascade Style Sheet (CSS) file (or SCSS if +sass-rails+ is in the +Gemfile+) file for that controller. For example, if a +ProjectsController+ is generated, there will be a new file at +app/assets/javascripts/projects.js.coffee+ and another at +app/assets/stylesheets/projects.css.scss+. You should put any JavaScript or CSS unique to a controller inside their respective asset files. +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 Cascade Style Sheet file (or SCSS if +sass-rails+ is in the +Gemfile+) file for that controller. For example, if a +ProjectsController+ is generated, there will be a new file at +app/assets/javascripts/projects.js.coffee+ and another at +app/assets/stylesheets/projects.css.scss+. You should put any JavaScript or CSS unique to a controller inside their respective asset files. h4. Asset Organization @@ -37,7 +37,7 @@ Any subdirectory that exists within these three locations will be added to the s h4. External Assets -Assets can also come from external sources such as engines. A good example of this is the +jquery-rails+ gem which comes with Rails 3.1 as standard. This gem contains an engine class which inherits from +Rails::Engine+. By doing this, Rails is informed that the directory for this gem may contain assets and the +app/assets+, +lib/assets+ and +vendor/assets+ directories of this engine are added to the search path of Sprockets. +Assets can also come from external sources such as engines. A good example of this is the +jquery-rails+ gem which comes with Rails as the standard JavaScript library gem. This gem contains an engine class which inherits from +Rails::Engine+. By doing this, Rails is informed that the directory for this gem may contain assets and the +app/assets+, +lib/assets+ and +vendor/assets+ directories of this engine are added to the search path of Sprockets. h4. Serving Assets -- cgit v1.2.3 From c01c954c20e64119ea73f3b71c4d843d66fda64e Mon Sep 17 00:00:00 2001 From: Mohammad Typaldos Date: Tue, 21 Jun 2011 04:23:35 -0700 Subject: Added Gzip to Asset Pipeline via GitHub --- railties/guides/source/asset_pipeline.textile | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties/guides/source') diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index d0c1faa80d..78683b743c 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -94,6 +94,8 @@ h4. Compressing Assets The default Gemfile also includes the "uglifier":https://github.com/lautis/uglifier gem. 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. +Sprockets also turns on "Gzip":http://en.wikipedia.org/wiki/Gzip (.gz) when possible (by checking the user's headers). Gzip is a file compression technique, much like the ever so popular "zip" file, except it's more open source friendly. Gzip should not modify the contents of the file, but simply the size of the file. + h4. Adding Assets to Your Gems To include your assets inside of a gem, simple package it in +lib/assets+ as you would in +app/assets+. You should append or prepend the name of your gem though, this should help avoid name conflicts with other gems or the user's application. -- cgit v1.2.3 From 98623a061ef56aa8427067b90b26f5b3b6151133 Mon Sep 17 00:00:00 2001 From: Mikhail Dieterle Date: Wed, 22 Jun 2011 03:04:28 -0700 Subject: Fixed typo --- railties/guides/source/form_helpers.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile index c7e45c0a23..4314d00f2e 100644 --- a/railties/guides/source/form_helpers.textile +++ b/railties/guides/source/form_helpers.textile @@ -777,7 +777,7 @@ If you need to post some data to an external resource it is still great to build Sometimes when you submit data to an external resource, like payment gateway, fields you can use in your form are limited by an external API. So you may want not to generate an +authenticity_token+ hidden field at all. For doing this just pass +false+ to the +:authenticity_token+ option: -<%= form_tag 'http://farfar.away/form', :authenticity_token => 'external_token') do %> +<%= form_tag 'http://farfar.away/form', :authenticity_token => false) do %> Form contents <% end %> -- cgit v1.2.3 From 95f827f9109a6f5d903496788326de1c0f9121c5 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 22 Jun 2011 19:40:51 +0530 Subject: font style changes in perf guide --- railties/guides/source/performance_testing.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/performance_testing.textile b/railties/guides/source/performance_testing.textile index a4187a3135..dbe6f97f5c 100644 --- a/railties/guides/source/performance_testing.textile +++ b/railties/guides/source/performance_testing.textile @@ -151,7 +151,7 @@ Performance tests can be run in two modes: Benchmarking and Profiling. h5. Benchmarking -Benchmarking makes it easy to quickly gather a few metrics about each test tun. By default, each test case is run +4 times+ in benchmarking mode. +Benchmarking makes it easy to quickly gather a few metrics about each test tun. By default, each test case is run *4 times* in benchmarking mode. To run performance tests in benchmarking mode: @@ -161,7 +161,7 @@ $ rake test:benchmark h5. Profiling -Profiling allows you to make an in-depth analysis of each of your tests by using an external profiler. Depending on your Ruby interpreter, this profiler can be native (Rubinius, JRuby) or not (MRI, which uses RubyProf). By default, each test case is run +1 time+ in profiling mode. +Profiling allows you to make an in-depth analysis of each of your tests by using an external profiler. Depending on your Ruby interpreter, this profiler can be native (Rubinius, JRuby) or not (MRI, which uses RubyProf). By default, each test case is run *once* in profiling mode. To run performance tests in profiling mode: -- cgit v1.2.3 From 06fe01a337ccf7f44bbaf272eddac284f80dcadb Mon Sep 17 00:00:00 2001 From: Mikhail Dieterle Date: Thu, 23 Jun 2011 03:08:32 -0700 Subject: updated rspec link --- railties/guides/source/testing.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile index db9c7545c8..cc55d1f756 100644 --- a/railties/guides/source/testing.textile +++ b/railties/guides/source/testing.textile @@ -944,7 +944,7 @@ The built-in +test/unit+ based testing is not the only way to test Rails applica * "Factory Girl":https://github.com/thoughtbot/factory_girl/tree/master, a replacement for fixtures. * "Machinist":https://github.com/notahat/machinist/tree/master, another replacement for fixtures. * "Shoulda":http://www.thoughtbot.com/projects/shoulda, an extension to +test/unit+ with additional helpers, macros, and assertions. -* "RSpec":http://rspec.info/, a behavior-driven development framework +* "RSpec":http://relishapp.com/rspec, a behavior-driven development framework h3. Changelog -- cgit v1.2.3