From 0ddec98b950ad73028c6c11f7d0b7a19e96687d7 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 2 May 2012 01:29:46 +0530 Subject: copy-edit guide [ci skip] --- guides/source/command_line.textile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'guides/source') diff --git a/guides/source/command_line.textile b/guides/source/command_line.textile index 95a01710b5..6dc78880f8 100644 --- a/guides/source/command_line.textile +++ b/guides/source/command_line.textile @@ -446,8 +446,7 @@ app/model/post.rb: NOTE. When using specific annotations and custom annotations, the annotation name (FIXME, BUG etc) is not displayed in the output lines. -Be default, rake notes will look in the app, config, lib, script and test directories for notes. If you would like to search additional directories, -simply provide the directories as a comma seperated list in an environment variable +SOURCE_ANNOTATION_DIRECTORIES+. +By default, +rake notes+ will look in the +app+, +config+, +lib+, +script+ and +test+ directories. If you would like to search other directories, you can provide them as a comma separated list in an environment variable +SOURCE_ANNOTATION_DIRECTORIES+. $ export SOURCE_ANNOTATION_DIRECTORIES='rspec,vendor' -- cgit v1.2.3 From 7273adabed9a3a7aa04014e50ec0ad077ee364aa Mon Sep 17 00:00:00 2001 From: Teng Siong Ong Date: Thu, 3 May 2012 03:28:32 -0500 Subject: cache_store has an extra option of :null_store. --- guides/source/configuring.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/configuring.textile b/guides/source/configuring.textile index 68426221bf..66e453c3ff 100644 --- a/guides/source/configuring.textile +++ b/guides/source/configuring.textile @@ -70,7 +70,7 @@ NOTE. The +config.asset_path+ configuration is ignored if the asset pipeline is * +config.action_view.cache_template_loading+ controls whether or not templates should be reloaded on each request. Defaults to whatever is set for +config.cache_classes+. -* +config.cache_store+ configures which cache store to use for Rails caching. Options include one of the symbols +:memory_store+, +:file_store+, +:mem_cache_store+, or an object that implements the cache API. Defaults to +:file_store+ if the directory +tmp/cache+ exists, and to +:memory_store+ otherwise. +* +config.cache_store+ configures which cache store to use for Rails caching. Options include one of the symbols +:memory_store+, +:file_store+, +:mem_cache_store+, +:null_store+, or an object that implements the cache API. Defaults to +:file_store+ if the directory +tmp/cache+ exists, and to +:memory_store+ otherwise. * +config.colorize_logging+ specifies whether or not to use ANSI color codes when logging information. Defaults to true. -- cgit v1.2.3 From 7a6116b633479effe81a820d84aaf29572cc3412 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Thu, 3 May 2012 22:26:30 -0300 Subject: Add some docs and changelog entry --- guides/source/configuring.textile | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'guides/source') diff --git a/guides/source/configuring.textile b/guides/source/configuring.textile index 66e453c3ff..71cc972517 100644 --- a/guides/source/configuring.textile +++ b/guides/source/configuring.textile @@ -76,6 +76,17 @@ NOTE. The +config.asset_path+ configuration is ignored if the asset pipeline is * +config.consider_all_requests_local+ is a flag. If true then any error will cause detailed debugging information to be dumped in the HTTP response, and the +Rails::Info+ controller will show the application runtime context in +/rails/info/properties+. True by default in development and test environments, and false in production mode. For finer-grained control, set this to false and implement +local_request?+ in controllers to specify which requests should provide debugging information on errors. +* +config.console+ allows you to set class that will be used as console you run +rails console+. It's best to run it in +console+ block: + + +console do + # this block is called only when running console, + # so we can safely require pry here + require "pry" + config.console = Pry +end + + * +config.dependency_loading+ is a flag that allows you to disable constant autoloading setting it to false. It only has effect if +config.cache_classes+ is true, which it is by default in production mode. This flag is set to false by +config.threadsafe!+. * +config.eager_load_paths+ accepts an array of paths from which Rails will eager load on boot if cache classes is enabled. Defaults to every folder in the +app+ directory of the application. @@ -100,6 +111,10 @@ NOTE. The +config.asset_path+ configuration is ignored if the asset pipeline is * +config.preload_frameworks+ enables or disables preloading all frameworks at startup. Enabled by +config.threadsafe!+. Defaults to +nil+, so is disabled. +* +config.queue+ configures a different queue implementation for the application. Defaults to +Rails::Queueing::Queue+. Note that, if the default queue is changed, the default +queue_consumer+ is not going to be initialized, it is up to the new queue implementation to handle starting and shutting down its own consumer(s). + +* +config.queue_consumer+ configures a different consumer implementation for the default queue. Defaults to +Rails::Queueing::ThreadedConsumer+. + * +config.reload_classes_only_on_change+ enables or disables reloading of classes only when tracked files change. By default tracks everything on autoload paths and is set to true. If +config.cache_classes+ is true, this option is ignored. * +config.secret_token+ used for specifying a key which allows sessions for the application to be verified against a known secure key to prevent tampering. Applications get +config.secret_token+ initialized to a random key in +config/initializers/secret_token.rb+. @@ -122,17 +137,6 @@ WARNING: Threadsafe operation is incompatible with the normal workings of develo * +config.whiny_nils+ enables or disables warnings when a certain set of methods are invoked on +nil+ and it does not respond to them. Defaults to true in development and test environments. -* +config.console+ allows you to set class that will be used as console you run +rails console+. It's best to run it in +console+ block: - - -console do - # this block is called only when running console, - # so we can safely require pry here - require "pry" - config.console = Pry -end - - 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. -- cgit v1.2.3 From 544a10e428cda02e7baa38586ef266daaef20d89 Mon Sep 17 00:00:00 2001 From: Mike Manewitz Date: Fri, 4 May 2012 10:24:56 -0500 Subject: Editing log levels to reflect this doc: http://api.rubyonrails.org/classes/ActiveSupport/BufferedLogger/Severity.html --- guides/source/debugging_rails_applications.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/debugging_rails_applications.textile b/guides/source/debugging_rails_applications.textile index 903ed59e7b..45fa4ada78 100644 --- a/guides/source/debugging_rails_applications.textile +++ b/guides/source/debugging_rails_applications.textile @@ -124,7 +124,7 @@ h4. Log Levels When something is logged it's printed into the corresponding log if the log level of the message is equal or higher than the configured log level. If you want to know the current log level you can call the +Rails.logger.level+ method. -The available log levels are: +:debug+, +:info+, +:warn+, +:error+, and +:fatal+, corresponding to the log level numbers from 0 up to 4 respectively. To change the default log level, use +The available log levels are: +:debug+, +:info+, +:warn+, +:error+, +:fatal+, and +:unknown+, corresponding to the log level numbers from 0 up to 5 respectively. To change the default log level, use config.log_level = :warn # In any environment initializer, or -- cgit v1.2.3 From 9d906d04ef09c585f215c0dcae6af05e0316831e Mon Sep 17 00:00:00 2001 From: Marcelo Silveira Date: Sat, 5 May 2012 13:15:09 -0300 Subject: Update `first`, `last` and `take` in guides --- guides/source/active_record_querying.textile | 50 +++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 8 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_record_querying.textile b/guides/source/active_record_querying.textile index f9dbaa1125..d16cdd66ee 100644 --- a/guides/source/active_record_querying.textile +++ b/guides/source/active_record_querying.textile @@ -99,9 +99,26 @@ SELECT * FROM clients WHERE (clients.id = 10) LIMIT 1 Model.find(primary_key) will raise an +ActiveRecord::RecordNotFound+ exception if no matching record is found. +h5. +take+ + +Model.take retrieves a record without any implicit ordering. The retrieved record may vary depending on the database engine. For example: + + +client = Client.take +# => # + + +The SQL equivalent of the above is: + + +SELECT * FROM clients LIMIT 1 + + +Model.take returns +nil+ if no record is found. No exception will be raised. + h5. +first+ -Model.first finds the first record matched by the supplied options, if any. For example: +Model.first finds the first record. If no order is chained it will order by primary key. For example: client = Client.first @@ -111,14 +128,14 @@ client = Client.first The SQL equivalent of the above is: -SELECT * FROM clients LIMIT 1 +SELECT * FROM clients ORDER BY clients.id ASC LIMIT 1 Model.first returns +nil+ if no matching record is found. No exception will be raised. h5. +last+ -Model.last finds the last record matched by the supplied options. For example: +Model.last finds the last record. If no order is chained it will order by primary key. For example: client = Client.last @@ -148,12 +165,29 @@ Client.find_by first_name: 'Jon' It is equivalent to writing: -Client.where(first_name: 'Lifo').first +Client.where(first_name: 'Lifo').take +h5(#take_1). +take!+ + +Model.take! retrieves a record without any implicit ordering. For example: + + +client = Client.take! +# => # + + +The SQL equivalent of the above is: + + +SELECT * FROM clients LIMIT 1 + + +Model.take! raises +RecordNotFound+ if no matching record is found. + h5(#first_1). +first!+ -Model.first! finds the first record. For example: +Model.first! finds the first record. If no order is chained it will order by primary key. For example: client = Client.first! @@ -163,14 +197,14 @@ client = Client.first! The SQL equivalent of the above is: -SELECT * FROM clients LIMIT 1 +SELECT * FROM clients ORDER BY clients.id ASC LIMIT 1 Model.first! raises +RecordNotFound+ if no matching record is found. h5(#last_1). +last!+ -Model.last! finds the last record. For example: +Model.last! finds the last record. If no order is chained it will order by primary key. For example: client = Client.last! @@ -200,7 +234,7 @@ Client.find_by! first_name: 'Jon' It is equivalent to writing: -Client.where(first_name: 'Lifo').first! +Client.where(first_name: 'Lifo').take! h4. Retrieving Multiple Objects -- cgit v1.2.3 From a9668680fd5eda2797f003a710eaf220768d95da Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 5 May 2012 23:54:16 +0530 Subject: some corrections in the AR query guide [ci skip] --- guides/source/active_record_querying.textile | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_record_querying.textile b/guides/source/active_record_querying.textile index d16cdd66ee..a9cb424eaa 100644 --- a/guides/source/active_record_querying.textile +++ b/guides/source/active_record_querying.textile @@ -101,7 +101,7 @@ SELECT * FROM clients WHERE (clients.id = 10) LIMIT 1 h5. +take+ -Model.take retrieves a record without any implicit ordering. The retrieved record may vary depending on the database engine. For example: +Model.take retrieves a record without any implicit ordering. For example: client = Client.take @@ -114,11 +114,13 @@ The SQL equivalent of the above is: SELECT * FROM clients LIMIT 1 -Model.take returns +nil+ if no record is found. No exception will be raised. +Model.take returns +nil+ if no record is found and no exception will be raised. + +TIP: The retrieved record may vary depending on the database engine. h5. +first+ -Model.first finds the first record. If no order is chained it will order by primary key. For example: +Model.first finds the first record ordered by the primary key. For example: client = Client.first @@ -131,11 +133,11 @@ The SQL equivalent of the above is: SELECT * FROM clients ORDER BY clients.id ASC LIMIT 1 -Model.first returns +nil+ if no matching record is found. No exception will be raised. +Model.first returns +nil+ if no matching record is found and no exception will be raised. h5. +last+ -Model.last finds the last record. If no order is chained it will order by primary key. For example: +Model.last finds the last record ordered by the primary key. For example: client = Client.last @@ -148,7 +150,7 @@ The SQL equivalent of the above is: SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1 -Model.last returns +nil+ if no matching record is found. No exception will be raised. +Model.last returns +nil+ if no matching record is found and no exception will be raised. h5. +find_by+ @@ -183,11 +185,11 @@ The SQL equivalent of the above is: SELECT * FROM clients LIMIT 1 -Model.take! raises +RecordNotFound+ if no matching record is found. +Model.take! raises +ActiveRecord::RecordNotFound+ if no matching record is found. h5(#first_1). +first!+ -Model.first! finds the first record. If no order is chained it will order by primary key. For example: +Model.first! finds the first record ordered by the primary key. For example: client = Client.first! @@ -200,11 +202,11 @@ The SQL equivalent of the above is: SELECT * FROM clients ORDER BY clients.id ASC LIMIT 1 -Model.first! raises +RecordNotFound+ if no matching record is found. +Model.first! raises +ActiveRecord::RecordNotFound+ if no matching record is found. h5(#last_1). +last!+ -Model.last! finds the last record. If no order is chained it will order by primary key. For example: +Model.last! finds the last record ordered by the primary key. For example: client = Client.last! @@ -217,18 +219,18 @@ The SQL equivalent of the above is: SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1 -Model.last! raises +RecordNotFound+ if no matching record is found. +Model.last! raises +ActiveRecord::RecordNotFound+ if no matching record is found. h5(#find_by_1). +find_by!+ -Model.find_by! finds the first record matching some conditions. It raises +RecordNotFound+ if no matching record is found. For example: +Model.find_by! finds the first record matching some conditions. It raises +ActiveRecord::RecordNotFound+ if no matching record is found. For example: Client.find_by! first_name: 'Lifo' # => # Client.find_by! first_name: 'Jon' -# => RecordNotFound +# => ActiveRecord::RecordNotFound It is equivalent to writing: -- cgit v1.2.3 From aa5dd1439b49ae0e4a0574238ade338f9d05080b Mon Sep 17 00:00:00 2001 From: Alexey Gaziev Date: Tue, 24 Apr 2012 14:05:38 +0400 Subject: Guides for deep_dup --- .../source/active_support_core_extensions.textile | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'guides/source') diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile index e4a6e145b9..98f9a67ca7 100644 --- a/guides/source/active_support_core_extensions.textile +++ b/guides/source/active_support_core_extensions.textile @@ -154,6 +154,40 @@ WARNING. Any class can disallow duplication removing +dup+ and +clone+ or raisin NOTE: Defined in +active_support/core_ext/object/duplicable.rb+. +h4. +deep_dup+ + +When data is very big and have many layers we need some recursive method to duplicate it right. For example, if we want to duplicate Array with some string inside and then work with this string as with part of duplicated object. + + +array = ['string'] +dup = array.dup +dup[0] << '?' +array.object_id == dup.object_id # => false +array[0] == dup[0] # => true + + +Active Support provides +deep_dup+ to dup all objects recursively inside deep dupilicated Array or Hash: + +If object can be duplicable - then it is just an alias for dup. + + +string = 'abc' +dup = string.deep_dup +string.object_id == dup.object_id # => false + + +If not - this method will return original object. + + +number = 1 +dup = number.deep_dup +number.object_id == dup.object_id # => true + + +WARNING. The same as in +duplicable?+ because +deep_dup+ uses that method. + +NOTE: Defined in +active_support/core_ext/object/deep_dup.rb+. + h4. +try+ Sometimes you want to call a method provided the receiver object is not +nil+, which is something you usually check first. +try+ is like +Object#send+ except that it returns +nil+ if sent to +nil+. @@ -2217,6 +2251,19 @@ Thus, in this case the behavior is different for +nil+, and the differences with NOTE: Defined in +active_support/core_ext/array/wrap.rb+. +h4. Duplicating + +The method +Array.deep_dup+ duplicates itself and all objects inside recursively with ActiveSupport method +Object#deep_dup+. It works like +Array#map+ with sending +deep_dup+ method to each object inside. + + +array = [1, [2, 3]] +dup = array.deep_dup +dup[1][2] = 4 +array[1][2] == nil # => true + + +NOTE: Defined in +active_support/core_ext/array/deep_dup.rb+. + h4. Grouping h5. +in_groups_of(number, fill_with = nil)+ @@ -2423,6 +2470,23 @@ The method +deep_merge!+ performs a deep merge in place. NOTE: Defined in +active_support/core_ext/hash/deep_merge.rb+. +h4. Deep duplicating + +The method +Hash.deep_dup+ duplicates itself and all keys and values inside recursively with ActiveSupport method +Object#deep_dup+. It works like +Enumerator#each_with_object+ with sending +deep_dup+ method to each pair inside. + + +hash = { :a => 1, :b => { :c => 2, :d => [3, 4] } } + +dup = hash.deep_dup +dup[:b][:e] = 5 +dup[:b][:d] << 5 + +hash[:b][:e] == nil # => true +hash[:b][:d] == [3, 4] # => true + + +NOTE: Defined in +active_support/core_ext/hash/deep_dup.rb+. + h4. Diffing The method +diff+ returns a hash that represents a diff of the receiver and the argument with the following logic: -- cgit v1.2.3 From 352d033ab9d9a03f3222aedefbc11e29a1fb5ffa Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sun, 6 May 2012 10:53:27 -0700 Subject: Reword guide entry for `deep_dup` method. --- .../source/active_support_core_extensions.textile | 37 ++++++++++++++-------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile index 98f9a67ca7..ab5ceaf2b3 100644 --- a/guides/source/active_support_core_extensions.textile +++ b/guides/source/active_support_core_extensions.textile @@ -156,27 +156,38 @@ NOTE: Defined in +active_support/core_ext/object/duplicable.rb+. h4. +deep_dup+ -When data is very big and have many layers we need some recursive method to duplicate it right. For example, if we want to duplicate Array with some string inside and then work with this string as with part of duplicated object. +The +deep_dup+ method returns deep copy of given object. Normally, when you +dup+ an object that contains other objects, ruby does not +dup+ them. If you have array with a string, for example, it will look like this: -array = ['string'] -dup = array.dup -dup[0] << '?' -array.object_id == dup.object_id # => false -array[0] == dup[0] # => true +array = ['string'] +duplicate = array.dup + +duplicate.push 'another-string' + +array #=> ['string'] +duplicate #=> ['string', 'another-string'] + +duplicate.first.gsub!('string', 'foo') + +array #=> ['foo'] +duplicate #=> ['foo', 'another-string'] -Active Support provides +deep_dup+ to dup all objects recursively inside deep dupilicated Array or Hash: +As you can see, after duplicating +Array+ instance, we got another object, therefore we can modify it and the original object will stay unchanged. This is not true for array's elements, however. Since +dup+ does not make deep copy, the string inside array is still the same object. -If object can be duplicable - then it is just an alias for dup. +If you need a deep copy of an object, you should use +deep_dup+ in such situation: -string = 'abc' -dup = string.deep_dup -string.object_id == dup.object_id # => false +array = ['string'] +duplicate = array.dup + +duplicate.first.gsub!('string', 'foo') + +array #=> ['string'] +duplicate #=> ['foo'] -If not - this method will return original object. +If object is not duplicable +deep_dup+ will just return this object: number = 1 @@ -184,8 +195,6 @@ dup = number.deep_dup number.object_id == dup.object_id # => true -WARNING. The same as in +duplicable?+ because +deep_dup+ uses that method. - NOTE: Defined in +active_support/core_ext/object/deep_dup.rb+. h4. +try+ -- cgit v1.2.3 From 3ac93d662933ee032227da0bcce57807c7d57889 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sun, 6 May 2012 19:06:49 -0700 Subject: [guides] Add comments to deep_dup example, fix second example [ci skip] --- guides/source/active_support_core_extensions.textile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile index ab5ceaf2b3..c56cb0b9e5 100644 --- a/guides/source/active_support_core_extensions.textile +++ b/guides/source/active_support_core_extensions.textile @@ -164,11 +164,13 @@ duplicate = array.dup duplicate.push 'another-string' +# object was duplicated, element added only to duplicate array #=> ['string'] duplicate #=> ['string', 'another-string'] duplicate.first.gsub!('string', 'foo') +# first element was not duplicated, it will be changed for both arrays array #=> ['foo'] duplicate #=> ['foo', 'another-string'] @@ -179,7 +181,7 @@ If you need a deep copy of an object, you should use +deep_dup+ in such situatio array = ['string'] -duplicate = array.dup +duplicate = array.deep_dup duplicate.first.gsub!('string', 'foo') -- cgit v1.2.3 From 552f535796b92df57ae7e7ea339307c45683c71b Mon Sep 17 00:00:00 2001 From: Mark Rushakoff Date: Sun, 6 May 2012 20:40:48 -0700 Subject: are ran -> are run The former is grammatically incorrect. --- guides/source/configuring.textile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'guides/source') diff --git a/guides/source/configuring.textile b/guides/source/configuring.textile index 59f12e98ab..5bfb45f778 100644 --- a/guides/source/configuring.textile +++ b/guides/source/configuring.textile @@ -182,13 +182,13 @@ The full set of methods that can be used in this block are as follows: * +force_plural+ allows pluralized model names. Defaults to +false+. * +helper+ defines whether or not to generate helpers. Defaults to +true+. * +integration_tool+ defines which integration tool to use. Defaults to +nil+. -* +javascripts+ turns on the hook for javascripts in generators. Used in Rails for when the +scaffold+ generator is ran. Defaults to +true+. +* +javascripts+ turns on the hook for javascripts in generators. Used in Rails for when the +scaffold+ generator is run. Defaults to +true+. * +javascript_engine+ configures the engine to be used (for eg. coffee) when generating assets. Defaults to +nil+. * +orm+ defines which orm to use. Defaults to +false+ and will use Active Record by default. * +performance_tool+ defines which performance tool to use. Defaults to +nil+. * +resource_controller+ defines which generator to use for generating a controller when using +rails generate resource+. Defaults to +:controller+. * +scaffold_controller+ different from +resource_controller+, defines which generator to use for generating a _scaffolded_ controller when using +rails generate scaffold+. Defaults to +:scaffold_controller+. -* +stylesheets+ turns on the hook for stylesheets in generators. Used in Rails for when the +scaffold+ generator is ran, but this hook can be used in other generates as well. Defaults to +true+. +* +stylesheets+ turns on the hook for stylesheets in generators. Used in Rails for when the +scaffold+ generator is run, but this hook can be used in other generates as well. Defaults to +true+. * +stylesheet_engine+ configures the stylesheet engine (for eg. sass) to be used when generating assets. Defaults to +:css+. * +test_framework+ defines which test framework to use. Defaults to +false+ and will use Test::Unit by default. * +template_engine+ defines which template engine to use, such as ERB or Haml. Defaults to +:erb+. @@ -585,13 +585,13 @@ TIP: If you have any ordering dependency in your initializers, you can control t h3. Initialization events -Rails has 5 initialization events which can be hooked into (listed in the order that they are ran): +Rails has 5 initialization events which can be hooked into (listed in the order that they are run): * +before_configuration+: This is run as soon as the application constant inherits from +Rails::Application+. The +config+ calls are evaluated before this happens. * +before_initialize+: This is run directly before the initialization process of the application occurs with the +:bootstrap_hook+ initializer near the beginning of the Rails initialization process. -* +to_prepare+: Run after the initializers are ran for all Railties (including the application itself), but before eager loading and the middleware stack is built. More importantly, will run upon every request in +development+, but only once (during boot-up) in +production+ and +test+. +* +to_prepare+: Run after the initializers are run for all Railties (including the application itself), but before eager loading and the middleware stack is built. More importantly, will run upon every request in +development+, but only once (during boot-up) in +production+ and +test+. * +before_eager_load+: This is run directly before eager loading occurs, which is the default behaviour for the _production_ environment and not for the +development+ environment. @@ -732,7 +732,7 @@ The error occurred while evaluating nil.each *+load_config_initializers+* Loads all Ruby files from +config/initializers+ in the application, railties and engines. The files in this directory can be used to hold configuration settings that should be made after all of the frameworks are loaded. -*+engines_blank_point+* Provides a point-in-initialization to hook into if you wish to do anything before engines are loaded. After this point, all railtie and engine initializers are ran. +*+engines_blank_point+* Provides a point-in-initialization to hook into if you wish to do anything before engines are loaded. After this point, all railtie and engine initializers are run. *+add_generator_templates+* Finds templates for generators at +lib/templates+ for the application, railities and engines and adds these to the +config.generators.templates+ setting, which will make the templates available for all generators to reference. -- cgit v1.2.3 From cf243be4d5c50d0df28b7a51f403584184a17fb2 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Mon, 7 May 2012 12:18:51 +0530 Subject: note that WIP guides are not in the index menu [ci skip] --- guides/source/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/index.html.erb b/guides/source/index.html.erb index 5439459b42..74805b2754 100644 --- a/guides/source/index.html.erb +++ b/guides/source/index.html.erb @@ -13,7 +13,7 @@ Ruby on Rails Guides and <%= link_to 'Free Kindle Reading Apps', 'http://www.amazon.com/gp/kindle/kcp' %> for the iPad, iPhone, Mac, Android, etc. Download them from <%= link_to 'here', @mobi %>. -
Guides marked with this icon are currently being worked on. While they might still be useful to you, they may contain incomplete information and even errors. You can help by reviewing them and posting your comments and corrections to the author.
+
Guides marked with this icon are currently being worked on and will not be available in the Guides Index menu. While still useful, they may contain incomplete information and even errors. You can help by reviewing them and posting your comments and corrections.
<% end %> -- cgit v1.2.3 From 8c4777f446d9e14deb077f44d31579a5a96e68ae Mon Sep 17 00:00:00 2001 From: "Mark J. Titorenko" Date: Mon, 7 May 2012 12:04:51 +0100 Subject: Added documentation for +beginning_of_hour+ and +end_of_hour+ to Active Support Core Extensions guide. --- .../source/active_support_core_extensions.textile | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'guides/source') diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile index e4a6e145b9..a238a84e8c 100644 --- a/guides/source/active_support_core_extensions.textile +++ b/guides/source/active_support_core_extensions.textile @@ -3064,6 +3064,28 @@ date.end_of_day # => Sun Jun 06 23:59:59 +0200 2010 +beginning_of_day+ is aliased to +at_beginning_of_day+, +midnight+, +at_midnight+. +h6. +beginning_of_hour+, +end_of_hour+ + +The method +beginning_of_hour+ returns a timestamp at the beginning of the hour (hh:00:00): + + +date = DateTime.new(2010, 6, 7, 19, 55, 25) +date.beginning_of_hour # => Mon Jun 07 19:00:00 +0200 2010 + + +The method +end_of_hour+ returns a timestamp at the end of the hour (hh:59:59): + + +date = DateTime.new(2010, 6, 7, 19, 55, 25) +date.end_of_hour # => Mon Jun 07 19:59:59 +0200 2010 + + ++beginning_of_hour+ is aliased to +at_beginning_of_hour+. + +INFO: +beginning_of_hour+ and +end_of_hour+ are implemented for +Time+ and +DateTime+ but *not* +Date+ as it does not make sense to request the beginning or end of an hour on a +Date+ instance. + +NOTE: All the following methods are defined in +active_support/core_ext/date/calculations.rb+. + h6. +ago+, +since+ The method +ago+ receives a number of seconds as argument and returns a timestamp those many seconds ago from midnight: @@ -3131,6 +3153,13 @@ since (in) On the other hand, +advance+ and +change+ are also defined and support more options, they are documented below. +The following methods are only implemented in +active_support/core_ext/date_time/calculations.rb+ as they only make sense when used with a +DateTime+ instance: + + +beginning_of_hour (at_beginning_of_hour) +end_of_hour + + h5. Named Datetimes h6. +DateTime.current+ @@ -3273,6 +3302,8 @@ ago since (in) beginning_of_day (midnight, at_midnight, at_beginning_of_day) end_of_day +beginning_of_hour (at_beginning_of_hour) +end_of_hour beginning_of_week (at_beginning_of_week) end_of_week (at_end_of_week) monday -- cgit v1.2.3 From f174e8dcef66446cb7483c48dc746887b29078b6 Mon Sep 17 00:00:00 2001 From: "Mark J. Titorenko" Date: Mon, 7 May 2012 12:07:35 +0100 Subject: Corrections to +beginning_of_day+ and +end_of_day+ example dates. --- guides/source/active_support_core_extensions.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile index a238a84e8c..c9e9a13c09 100644 --- a/guides/source/active_support_core_extensions.textile +++ b/guides/source/active_support_core_extensions.textile @@ -3052,14 +3052,14 @@ The method +beginning_of_day+ returns a timestamp at the beginning of the day (0 date = Date.new(2010, 6, 7) -date.beginning_of_day # => Sun Jun 07 00:00:00 +0200 2010 +date.beginning_of_day # => Mon Jun 07 00:00:00 +0200 2010 The method +end_of_day+ returns a timestamp at the end of the day (23:59:59): date = Date.new(2010, 6, 7) -date.end_of_day # => Sun Jun 06 23:59:59 +0200 2010 +date.end_of_day # => Mon Jun 07 23:59:59 +0200 2010 +beginning_of_day+ is aliased to +at_beginning_of_day+, +midnight+, +at_midnight+. -- cgit v1.2.3 From 61587b18d2b4b03041cc7e54da00cff6344abeec Mon Sep 17 00:00:00 2001 From: "Mark J. Titorenko" Date: Mon, 7 May 2012 12:24:40 +0100 Subject: Remove accidentally pasted NOTE section during introduction of +beginning_of_hour+ and +end_of_hour+ documentation. --- guides/source/active_support_core_extensions.textile | 2 -- 1 file changed, 2 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile index c9e9a13c09..43dc0c12cf 100644 --- a/guides/source/active_support_core_extensions.textile +++ b/guides/source/active_support_core_extensions.textile @@ -3084,8 +3084,6 @@ date.end_of_hour # => Mon Jun 07 19:59:59 +0200 2010 INFO: +beginning_of_hour+ and +end_of_hour+ are implemented for +Time+ and +DateTime+ but *not* +Date+ as it does not make sense to request the beginning or end of an hour on a +Date+ instance. -NOTE: All the following methods are defined in +active_support/core_ext/date/calculations.rb+. - h6. +ago+, +since+ The method +ago+ receives a number of seconds as argument and returns a timestamp those many seconds ago from midnight: -- cgit v1.2.3 From 66e0e4216c55c29557a2789a96c3847a901ccb30 Mon Sep 17 00:00:00 2001 From: Alexey Gaziev Date: Mon, 30 Apr 2012 00:40:19 +0400 Subject: Fix some guides for AS core_ext --- .../source/active_support_core_extensions.textile | 130 +++++++++++---------- 1 file changed, 66 insertions(+), 64 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile index e4a6e145b9..4bee3e400e 100644 --- a/guides/source/active_support_core_extensions.textile +++ b/guides/source/active_support_core_extensions.textile @@ -1034,49 +1034,6 @@ A model may find it useful to set +:instance_accessor+ to +false+ as a way to pr NOTE: Defined in +active_support/core_ext/class/attribute_accessors.rb+. -h4. Class Inheritable Attributes - -WARNING: Class Inheritable Attributes are deprecated. It's recommended that you use +Class#class_attribute+ instead. - -Class variables are shared down the inheritance tree. Class instance variables are not shared, but they are not inherited either. The macros +class_inheritable_reader+, +class_inheritable_writer+, and +class_inheritable_accessor+ provide accessors for class-level data which is inherited but not shared with children: - - -module ActionController - class Base - # FIXME: REVISE/SIMPLIFY THIS COMMENT. - # The value of allow_forgery_protection is inherited, - # but its value in a particular class does not affect - # the value in the rest of the controllers hierarchy. - class_inheritable_accessor :allow_forgery_protection - end -end - - -They accomplish this with class instance variables and cloning on subclassing, there are no class variables involved. Cloning is performed with +dup+ as long as the value is duplicable. - -There are some variants specialised in arrays and hashes: - - -class_inheritable_array -class_inheritable_hash - - -Those writers take any inherited array or hash into account and extend them rather than overwrite them. - -As with vanilla class attribute accessors these macros create convenience instance methods for reading and writing. The generation of the writer instance method can be prevented setting +:instance_writer+ to +false+ (not any false value, but exactly +false+): - - -module ActiveRecord - class Base - class_inheritable_accessor :default_scoping, :instance_writer => false - end -end - - -Since values are copied when a subclass is defined, if the base class changes the attribute after that, the subclass does not see the new value. That's the point. - -NOTE: Defined in +active_support/core_ext/class/inheritable_attributes.rb+. - h4. Subclasses & Descendants h5. +subclasses+ @@ -1255,9 +1212,14 @@ Pass a +:separator+ to truncate the string at a natural break: # => "Oh dear! Oh..."
-In the above example "dear" gets cut first, but then +:separator+ prevents it. +The option +:separator+ can be a regexp: + + +"Oh dear! Oh dear! I shall be late!".truncate(18, :separator => /\s/) +# => "Oh dear! Oh..." + -WARNING: The option +:separator+ can't be a regexp. +In above examples "dear" gets cut first, but then +:separator+ prevents it. NOTE: Defined in +active_support/core_ext/string/filters.rb+. @@ -1810,6 +1772,43 @@ Singular forms are aliased so you are able to say: NOTE: Defined in +active_support/core_ext/numeric/bytes.rb+. +h4. Time + +Enables the use of time calculations and declarations, like 45.minutes + 2.hours + 4.years. + +These methods use Time#advance for precise date calculations when using from_now, ago, etc. +as well as adding or subtracting their results from a Time object. For example: + + +# equivalent to Time.now.advance(:months => 1) +1.month.from_now + +# equivalent to Time.now.advance(:years => 2) +2.years.from_now + +# equivalent to Time.now.advance(:months => 4, :years => 5) +(4.months + 5.years).from_now + + +While these methods provide precise calculation when used as in the examples above, care +should be taken to note that this is not true if the result of `months', `years', etc is +converted before use: + + +# equivalent to 30.days.to_i.from_now +1.month.to_i.from_now + +# equivalent to 365.25.days.to_f.from_now +1.year.to_f.from_now + + +In such cases, Ruby's core +Date[http://ruby-doc.org/stdlib/libdoc/date/rdoc/Date.html] and +Time[http://ruby-doc.org/stdlib/libdoc/time/rdoc/Time.html] should be used for precision +date and time arithmetic. + +NOTE: Defined in +active_support/core_ext/numeric/time.rb+. + h3. Extensions to +Integer+ h4. +multiple_of?+ @@ -2103,20 +2102,20 @@ To do so it sends +to_xml+ to every item in turn, and collects the results under By default, the name of the root element is the underscorized and dasherized plural of the name of the class of the first item, provided the rest of elements belong to that type (checked with is_a?) and they are not hashes. In the example above that's "contributors". -If there's any element that does not belong to the type of the first one the root node becomes "records": +If there's any element that does not belong to the type of the first one the root node becomes "objects": [Contributor.first, Commit.first].to_xml # => # -# -# +# +# # 4583 # Aaron Batalion # 53 # aaron-batalion -# -# +# +# # Joshua Peek # 2009-09-02T16:44:36Z # origin/master @@ -2127,30 +2126,30 @@ If there's any element that does not belong to the type of the first one the roo # false # Kill AMo observing wrap_with_notifications since ARes was only using it # 723a47bfb3708f968821bc969a9a3fc873a3ed58 -# -# +# +# -If the receiver is an array of hashes the root element is by default also "records": +If the receiver is an array of hashes the root element is by default also "objects": [{:a => 1, :b => 2}, {:c => 3}].to_xml # => # -# -# +# +# # 2 # 1 -# -# +# +# # 3 -# -# +# +# WARNING. If the collection is empty the root element is by default "nil-classes". That's a gotcha, for example the root element of the list of contributors above would not be "contributors" if the collection was empty, but "nil-classes". You may use the :root option to ensure a consistent root element. -The name of children nodes is by default the name of the root node singularized. In the examples above we've seen "contributor" and "record". The option :children allows you to set these node names. +The name of children nodes is by default the name of the root node singularized. In the examples above we've seen "contributor" and "object". The option :children allows you to set these node names. The default XML builder is a fresh instance of Builder::XmlMarkup. You can configure your own builder via the :builder option. The method also accepts options like :dasherize and friends, they are forwarded to the builder: @@ -2707,22 +2706,25 @@ NOTE: Defined in +active_support/core_ext/range/blockless_step.rb+. h4. +include?+ -The method +Range#include?+ says whether some value falls between the ends of a given instance: +The methods +Range#include?+ and +Range#===+ say whether some value falls between the ends of a given instance: (2..3).include?(Math::E) # => true -Active Support extends this method so that the argument may be another range in turn. In that case we test whether the ends of the argument range belong to the receiver themselves: +Active Support extends these methods so that the argument may be another range in turn. In that case we test whether the ends of the argument range belong to the receiver themselves: (1..10).include?(3..7) # => true (1..10).include?(0..7) # => false (1..10).include?(3..11) # => false (1...9).include?(3..9) # => false - -WARNING: The original +Range#include?+ is still the one aliased to +Range#===+. +(1..10) === (3..7) # => true +(1..10) === (0..7) # => false +(1..10) === (3..11) # => false +(1...9) === (3..9) # => false +
NOTE: Defined in +active_support/core_ext/range/include_range.rb+. -- cgit v1.2.3 From d785b292a8c921989f606696dff3765836d1fb44 Mon Sep 17 00:00:00 2001 From: Alexey Gaziev Date: Mon, 7 May 2012 22:40:59 +0400 Subject: Changes for numeric api for Time because Time.current works different --- guides/source/active_support_core_extensions.textile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile index 4bee3e400e..52c1cea4b9 100644 --- a/guides/source/active_support_core_extensions.textile +++ b/guides/source/active_support_core_extensions.textile @@ -184,7 +184,7 @@ You can evaluate code in the context of any object's singleton class using +clas class Proc def bind(object) - block, time = self, Time.now + block, time = self, Time.current object.class_eval do method_name = "__bind_#{time.to_i}_#{time.usec}" define_method(method_name, &block) @@ -1780,13 +1780,13 @@ These methods use Time#advance for precise date calculations when using from_now as well as adding or subtracting their results from a Time object. For example: -# equivalent to Time.now.advance(:months => 1) +# equivalent to Time.current.advance(:months => 1) 1.month.from_now -# equivalent to Time.now.advance(:years => 2) +# equivalent to Time.current.advance(:years => 2) 2.years.from_now -# equivalent to Time.now.advance(:months => 4, :years => 5) +# equivalent to Time.current.advance(:months => 4, :years => 5) (4.months + 5.years).from_now -- cgit v1.2.3 From 3a6ffbbe42688f40edc8e0a12d0f556ef3720b9d Mon Sep 17 00:00:00 2001 From: Nick Novitski Date: Wed, 9 May 2012 13:20:19 -0700 Subject: remove inappropriate comma A qualifying clause beginning with words like "as", "if", or "although" should have a comma separating it from any following clauses in a sentence, but should not have a comma immediately after the beginning word, unless it is to separate a third, non-essential clause. Example 1: "Although I would quite like to go to lunch with you, I find myself instead writing a detailed commit message to justify a single-character documentation change." Example 2: "Despite, as you might well imagine, wishing I hadn't even noticed it in the first place, I still felt the error was worth correcting." --- guides/source/security.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/security.textile b/guides/source/security.textile index ac64b82bf6..ac55d60368 100644 --- a/guides/source/security.textile +++ b/guides/source/security.textile @@ -627,7 +627,7 @@ h4. Whitelists versus Blacklists -- _When sanitizing, protecting or verifying something, whitelists over blacklists._ -A blacklist can be a list of bad e-mail addresses, non-public actions or bad HTML tags. This is opposed to a whitelist which lists the good e-mail addresses, public actions, good HTML tags and so on. Although, sometimes it is not possible to create a whitelist (in a SPAM filter, for example), _(highlight)prefer to use whitelist approaches_: +A blacklist can be a list of bad e-mail addresses, non-public actions or bad HTML tags. This is opposed to a whitelist which lists the good e-mail addresses, public actions, good HTML tags and so on. Although sometimes it is not possible to create a whitelist (in a SPAM filter, for example), _(highlight)prefer to use whitelist approaches_: * Use before_filter :only => [...] instead of :except => [...]. This way you don't forget to turn it off for newly added actions. * Use attr_accessible instead of attr_protected. See the mass-assignment section for details -- cgit v1.2.3 From c8f5a216df7d14463027425b53968d7f7023bf85 Mon Sep 17 00:00:00 2001 From: Ben Wilhelm Date: Thu, 10 May 2012 11:15:32 -0700 Subject: Modified template in sample is new.html.erb, not index.html.erb --- guides/source/getting_started.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile index 947abd7ba0..1e9bd1f144 100644 --- a/guides/source/getting_started.textile +++ b/guides/source/getting_started.textile @@ -717,7 +717,7 @@ If you reload try to save a post without a title, Rails will send you back to the form, but that's not very useful. You need to tell the user that something went wrong. To do that, you'll modify -+app/views/posts/index.html.erb+ to check for error messages: ++app/views/posts/new.html.erb+ to check for error messages: <%= form_for :post, :url => { :action => :create } do |f| %> -- cgit v1.2.3 From c9a4e65217cc0711f264410484d23fb8b519b660 Mon Sep 17 00:00:00 2001 From: Egor Homakov Date: Fri, 11 May 2012 14:48:02 +0400 Subject: Update guides/source/configuring.textile --- guides/source/configuring.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/configuring.textile b/guides/source/configuring.textile index c4e54348d4..bed8ce3eb6 100644 --- a/guides/source/configuring.textile +++ b/guides/source/configuring.textile @@ -448,7 +448,7 @@ There are a few configuration options available in Active Support: * +config.active_support.bare+ enables or disables the loading of +active_support/all+ when booting Rails. Defaults to +nil+, which means +active_support/all+ is loaded. -* +config.active_support.escape_html_entities_in_json+ enables or disables the escaping of HTML entities in JSON serialization. Defaults to +true+. +* +config.active_support.escape_html_entities_in_json+ enables or disables the escaping of HTML entities in JSON serialization. Defaults to +false+. * +config.active_support.use_standard_json_time_format+ enables or disables serializing dates to ISO 8601 format. Defaults to +false+. -- cgit v1.2.3 From d4f4b858d3c493ea74a1e4ed8ed6566bfa4c7e27 Mon Sep 17 00:00:00 2001 From: Egor Homakov Date: Fri, 11 May 2012 15:40:03 +0400 Subject: Update guides/source/configuring.textile --- guides/source/configuring.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/configuring.textile b/guides/source/configuring.textile index bed8ce3eb6..b2c9300034 100644 --- a/guides/source/configuring.textile +++ b/guides/source/configuring.textile @@ -450,7 +450,7 @@ There are a few configuration options available in Active Support: * +config.active_support.escape_html_entities_in_json+ enables or disables the escaping of HTML entities in JSON serialization. Defaults to +false+. -* +config.active_support.use_standard_json_time_format+ enables or disables serializing dates to ISO 8601 format. Defaults to +false+. +* +config.active_support.use_standard_json_time_format+ enables or disables serializing dates to ISO 8601 format. Defaults to +true+. * +ActiveSupport::BufferedLogger.silencer+ is set to +false+ to disable the ability to silence logging in a block. The default is +true+. -- cgit v1.2.3 From 1004ccc84b16a78d9aa3180e57dda278002fe53e Mon Sep 17 00:00:00 2001 From: Eric Carty-Fickes Date: Fri, 11 May 2012 11:12:32 -0500 Subject: Clarify expire_action with namespaced controllers --- guides/source/caching_with_rails.textile | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'guides/source') diff --git a/guides/source/caching_with_rails.textile b/guides/source/caching_with_rails.textile index e455b504ce..34a100cd3a 100644 --- a/guides/source/caching_with_rails.textile +++ b/guides/source/caching_with_rails.textile @@ -229,6 +229,42 @@ class ProductsController < ActionController end +Sometimes it is necessary to disambiguate the controller when you call +expire_action+, such as when there are two identically named controllers in separate namespaces: + + +class ProductsController < ActionController + caches_action :index + + def index + @products = Product.all + end +end + +module Admin + class ProductsController < ActionController + cache_sweeper :product_sweeper + + def new + @product = Product.new + end + + def create + @product = Product.create(params[:product]) + end + end +end + +class ProductSweeper < ActionController::Caching::Sweeper + observe Product + + def after_create(product) + expire_action(:controller => '/products', :action => 'index') + end +end + + +Note the use of '/products' here rather than 'products'. If you wanted to expire an action cache for the +Admin::ProductsController+, you would use 'admin/products' instead. + h4. SQL Caching Query caching is a Rails feature that caches the result set returned by each query so that if Rails encounters the same query again for that request, it will use the cached result set as opposed to running the query against the database again. -- cgit v1.2.3 From a0d9b7903588cd988c8c9b4164494c792344f43e Mon Sep 17 00:00:00 2001 From: Scott Johnson <7.scott.j@gmail.com> Date: Fri, 11 May 2012 13:42:37 -0500 Subject: update engines guide to show how to have an engine's ApplicationController inherit from the main application's ApplicationController --- guides/source/engines.textile | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'guides/source') diff --git a/guides/source/engines.textile b/guides/source/engines.textile index 71bcf6b713..b94ede44c4 100644 --- a/guides/source/engines.textile +++ b/guides/source/engines.textile @@ -448,6 +448,8 @@ rake db:migrate SCOPE=blorgh VERSION=0 h4. Using a class provided by the application +h5. Using a model provided by the application + When an engine is created, it may want to use specific classes from an application to provide links between the pieces of the engine and the pieces of the application. In the case of the +blorgh+ engine, making posts and comments have authors would make a lot of sense. Usually, an application would have a +User+ class that would provide the objects that would represent the posts' and comments' authors, but there could be a case where the application calls this class something different, such as +Person+. It's because of this reason that the engine should not hardcode the associations to be exactly for a +User+ class, but should allow for some flexibility around what the class is called. @@ -544,6 +546,19 @@ end Now instead of the ugly Ruby object output the author's name will be displayed. +h5. Using a controller provided by the application + +Because Rails controllers generally share code for for things like authentication and accessing session variables, by default they inherit from ApplicationController. Rails engines, however are scoped to run independently from the main application, so each engine gets a scoped ApplicationController. This namespace prevents code collisions, but often engine controllers should access methods in the main application's ApplicationController. An easy way to provide this acess is to change the engine's scoped ApplicationController to inherit from the main application's ApplicationController. For our Blorgh engine this would be done by changing +app/controllers/blorgh/application_controller.rb+ to look like: + + + class Blorgh::ApplicationController < ApplicationController + end + + +By default, the engine's controllers inherit from Blorgh::ApplicationController. So, after making this change they will have access to the main applications ApplicationController as though they were part of the main application. + +This change does require that the engine is run from a Rails application that has an ApplicationController. + h4. Configuring an engine This section covers firstly how you can make the +user_class+ setting of the Blorgh engine configurable, followed by general configuration tips for the engine. -- cgit v1.2.3 From d897255f8a25c72aa72f14d2f82cb87058447fac Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 12 May 2012 18:07:10 +0530 Subject: copy editing [ci skip] --- guides/source/engines.textile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'guides/source') diff --git a/guides/source/engines.textile b/guides/source/engines.textile index b94ede44c4..880be57fb5 100644 --- a/guides/source/engines.textile +++ b/guides/source/engines.textile @@ -548,16 +548,16 @@ Now instead of the ugly Ruby object output the author's name will be displayed. h5. Using a controller provided by the application -Because Rails controllers generally share code for for things like authentication and accessing session variables, by default they inherit from ApplicationController. Rails engines, however are scoped to run independently from the main application, so each engine gets a scoped ApplicationController. This namespace prevents code collisions, but often engine controllers should access methods in the main application's ApplicationController. An easy way to provide this acess is to change the engine's scoped ApplicationController to inherit from the main application's ApplicationController. For our Blorgh engine this would be done by changing +app/controllers/blorgh/application_controller.rb+ to look like: +Because Rails controllers generally share code for things like authentication and accessing session variables, by default they inherit from ApplicationController. Rails engines, however are scoped to run independently from the main application, so each engine gets a scoped +ApplicationController+. This namespace prevents code collisions, but often engine controllers should access methods in the main application's +ApplicationController+. An easy way to provide this access is to change the engine's scoped +ApplicationController+ to inherit from the main application's +ApplicationController+. For our Blorgh engine this would be done by changing +app/controllers/blorgh/application_controller.rb+ to look like: - class Blorgh::ApplicationController < ApplicationController - end +class Blorgh::ApplicationController < ApplicationController +end -By default, the engine's controllers inherit from Blorgh::ApplicationController. So, after making this change they will have access to the main applications ApplicationController as though they were part of the main application. +By default, the engine's controllers inherit from Blorgh::ApplicationController. So, after making this change they will have access to the main applications +ApplicationController+ as though they were part of the main application. -This change does require that the engine is run from a Rails application that has an ApplicationController. +This change does require that the engine is run from a Rails application that has an +ApplicationController+. h4. Configuring an engine -- cgit v1.2.3 From 26e2c082595ecca360954cfc20ecc52221748f7b Mon Sep 17 00:00:00 2001 From: Richard Hulse Date: Sun, 13 May 2012 14:16:50 +1200 Subject: [guides] add local precompilation section --- guides/source/asset_pipeline.textile | 37 +++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/asset_pipeline.textile b/guides/source/asset_pipeline.textile index 010154f1d1..59f106acb2 100644 --- a/guides/source/asset_pipeline.textile +++ b/guides/source/asset_pipeline.textile @@ -396,7 +396,7 @@ Rails comes bundled with a rake task to compile the asset manifests and other fi Compiled assets are written to the location specified in +config.assets.prefix+. By default, this is the +public/assets+ directory. -You can call this task on the server during deployment to create compiled versions of your assets directly on the server. If you do not have write access to your production file system, you can call this task locally and then deploy the compiled assets. +You can call this task on the server during deployment to create compiled versions of your assets directly on the server. See the next section for information on compiling locally. The rake task is: @@ -516,6 +516,41 @@ If you're compiling nginx with Phusion Passenger you'll need to pass that option A robust configuration for Apache is possible but tricky; please Google around. (Or help update this Guide if you have a good example configuration for Apache.) +h4. Local Precompilation + +There are several reasons why you might precompile your assets locally. Among them are: + +* You may not have write access to your production file system. +* You may be deploying to more than one server, and want to avoid the duplication of work. +* You may be doing frequent deploys that do not include asset changes. + +Local compilation allows you to commit the compiled files into source control, and deploy as normal. + +There are two caveats: + +* You must not run the Capistrano deployment task. +* You must change the following two application configuration settings. + +In development.rb place the following line: + + +config.assets.prefix = "/dev-assets" + + +You will also need this in application.rb: + + +config.assets.initialize_on_precompile = false + + +The +prefix+ change makes rails use a different URL for serving assets in development mode, and so pass all requests to Sprockets. Production is still set to +/assets+. Without this changes the application would serve the precompiled assets in development, and you would not see any local changes until you next compiled assets. + +The +initialize_on_precompile+ change tell the precompile task to run without invoking Rails. + +You will also need to ensure that any compressors or minifers are available on you development system. + +In practice, this will allow you to precompile locally, have those files in your working tree, and commit those files to source control when needed. Development mode will work as expected. + h4. Live Compilation In some circumstances you may wish to use live compilation. In this mode all requests for assets in the pipeline are handled by Sprockets directly. -- cgit v1.2.3 From e6e6f4ef8675ea001801362b42cdabb13801da67 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Mon, 14 May 2012 06:52:50 +1000 Subject: Briefly explain static file routing in the getting started guide --- guides/source/getting_started.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile index 1e9bd1f144..bdd385918f 100644 --- a/guides/source/getting_started.textile +++ b/guides/source/getting_started.textile @@ -193,7 +193,7 @@ Now that we have made the controller and view, we need to tell Rails when we wan To fix this, delete the +index.html+ file located inside the +public+ directory of the application. -You need to do this because Rails will serve any static file in the +public+ directory that matches a route in preference to any dynamic content you generate from the controllers. +You need to do this because Rails will serve any static file in the +public+ directory that matches a route in preference to any dynamic content you generate from the controllers. The +index.html+ file is special: it will be served if a request comes in at the root route, e.g. http://localhost:3000. If another request such as http://localhost:3000/welcome happened, a static file at public/welcome.html would be served first, but only if it existed. Next, you have to tell Rails where your actual home page is located. -- cgit v1.2.3 From 9e4fd33ae8860388cff54af44ee07f19a09ba9f6 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Mon, 14 May 2012 06:54:40 +1000 Subject: Re-enforce/re-explain what happens when you go to root route (Welcome#index) better --- guides/source/getting_started.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile index bdd385918f..a689cf1c3b 100644 --- a/guides/source/getting_started.textile +++ b/guides/source/getting_started.textile @@ -210,7 +210,7 @@ Blog::Application.routes.draw do The +root :to => "welcome#index"+ tells Rails to map requests to the root of the application to the welcome controller's index action. This was created earlier when you ran the controller generator (+rails generate controller welcome index+). -If you navigate to "http://localhost:3000":http://localhost:3000 in your browser, you'll see +Hello, Rails!+. +If you navigate to "http://localhost:3000":http://localhost:3000 in your browser, you'll see the +Hello, Rails!+ message you put into +app/views/welcome/index.html.erb+, indicating that this new route is indeed going to +WelcomeController+'s +index+ action and is rendering the view correctly. NOTE. For more information about routing, refer to "Rails Routing from the Outside In":routing.html. -- cgit v1.2.3 From 96fb77fe8000569ccc6b5bfd91668719bf92fa3d Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Mon, 14 May 2012 06:55:45 +1000 Subject: Separate CR out in CRUD explanation, explain each letter one at a time --- guides/source/getting_started.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile index a689cf1c3b..540084eb15 100644 --- a/guides/source/getting_started.textile +++ b/guides/source/getting_started.textile @@ -220,7 +220,7 @@ Now that you've seen how to create a controller, an action and a view, let's cre In the Blog application, you will now create a new _resource_. A resource is the term used for a collection of similar objects, such as posts, people or animals. You can create, read, update and destroy items for a resource and these operations are referred to as _CRUD_ operations. -In the next section, you will add the ability to create new posts in your application and be able to view them. This is the "CR" from CRUD. The form for doing this will look like this: +In the next section, you will add the ability to create new posts in your application and be able to view them. This is the "C" and the "R" from CRUD: creation and reading. The form for doing this will look like this: !images/getting_started/new_post.png(The new post form)! -- cgit v1.2.3 From dbd131fc0e9394438eb0e76796c89160a924b7ef Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Mon, 14 May 2012 06:56:43 +1000 Subject: Rails actually has one root route defined --- guides/source/getting_started.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile index 540084eb15..3a5868b13e 100644 --- a/guides/source/getting_started.textile +++ b/guides/source/getting_started.textile @@ -232,7 +232,7 @@ The first thing that you are going to need to create a new post within the appli !images/getting_started/routing_error_no_route_matches.png(A routing error, no route matches /posts/new)! -This is because there is nowhere inside the routes for the application -- defined inside +config/routes.rb+ -- that defines this route. By default, Rails has no routes configured at all, and so you must define your routes as you need them. +This is because there is nowhere inside the routes for the application -- defined inside +config/routes.rb+ -- that defines this route. By default, Rails has no routes configured at all, besides the root route you defined earlier, and so you must define your routes as you need them. To do this, you're going to need to create a route inside +config/routes.rb+ file, on a new line between the +do+ and the +end+ for the +draw+ method: -- cgit v1.2.3 From 5f7caff82572daa2adc9a83f280b58572b3ba3e2 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Mon, 14 May 2012 07:02:58 +1000 Subject: Wrap 'Missing template posts/new' error message in a blockquote for better formatting --- guides/source/getting_started.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'guides/source') diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile index 3a5868b13e..6a07f87abd 100644 --- a/guides/source/getting_started.textile +++ b/guides/source/getting_started.textile @@ -282,9 +282,9 @@ You're getting this error now because Rails expects plain actions like this one In the above image, the bottom line has been truncated. Let's see what the full thing looks like: - +
Missing template posts/new, application/new with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/path/to/blog/app/views" - +
That's quite a lot of text! Let's quickly go through and understand what each part of it does. -- cgit v1.2.3 From d4801d0229515aae37d8f7a2f72c83990d2d977b Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Mon, 14 May 2012 07:06:41 +1000 Subject: Correct code wrapping around content of welcome/index.html.erb --- guides/source/getting_started.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'guides/source') diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile index 6a07f87abd..84c438e607 100644 --- a/guides/source/getting_started.textile +++ b/guides/source/getting_started.textile @@ -183,9 +183,9 @@ Rails will create several files for you. Most important of these are of course t Open the +app/views/welcome/index.html.erb+ file in your text editor and edit it to contain a single line of code: - +

Hello, Rails!

-
+ h4. Setting the Application Home Page -- cgit v1.2.3 From 8ef67de03409d0d21e42605e063e501d3ee764cf Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Mon, 14 May 2012 15:17:59 +0530 Subject: fix format in getting started guide [ci skip] --- guides/source/getting_started.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile index 84c438e607..e89602218e 100644 --- a/guides/source/getting_started.textile +++ b/guides/source/getting_started.textile @@ -193,7 +193,7 @@ Now that we have made the controller and view, we need to tell Rails when we wan To fix this, delete the +index.html+ file located inside the +public+ directory of the application. -You need to do this because Rails will serve any static file in the +public+ directory that matches a route in preference to any dynamic content you generate from the controllers. The +index.html+ file is special: it will be served if a request comes in at the root route, e.g. http://localhost:3000. If another request such as http://localhost:3000/welcome happened, a static file at public/welcome.html would be served first, but only if it existed. +You need to do this because Rails will serve any static file in the +public+ directory that matches a route in preference to any dynamic content you generate from the controllers. The +index.html+ file is special: it will be served if a request comes in at the root route, e.g. http://localhost:3000. If another request such as http://localhost:3000/welcome happened, a static file at public/welcome.html would be served first, but only if it existed. Next, you have to tell Rails where your actual home page is located. -- cgit v1.2.3 From ee4e48eab06659b3fea64c70590e8d260a230445 Mon Sep 17 00:00:00 2001 From: Ayrton De Craene Date: Mon, 14 May 2012 13:24:32 +0200 Subject: Improved the readability of some sentences [ci skip] --- guides/source/i18n.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/i18n.textile b/guides/source/i18n.textile index 6179694c40..a9da843d04 100644 --- a/guides/source/i18n.textile +++ b/guides/source/i18n.textile @@ -127,7 +127,7 @@ If you want to translate your Rails application to a *single language other than However, you would probably like to *provide support for more locales* in your application. In such case, you need to set and pass the locale between requests. -WARNING: You may be tempted to store the chosen locale in a _session_ or a cookie. *Do not do so*. The locale should be transparent and a part of the URL. This way you don't break people's basic assumptions about the web itself: if you send a URL of some page to a friend, she should see the same page, same content. A fancy word for this would be that you're being "RESTful":http://en.wikipedia.org/wiki/Representational_State_Transfer. Read more about the RESTful approach in "Stefan Tilkov's articles":http://www.infoq.com/articles/rest-introduction. There may be some exceptions to this rule, which are discussed below. +WARNING: You may be tempted to store the chosen locale in a _session_ or a cookie, however *do not do this*. The locale should be transparent and a part of the URL. This way you won't break people's basic assumptions about the web itself: if you send a URL to a friend, they should see the same page and content as you. A fancy word for this would be that you're being "RESTful":http://en.wikipedia.org/wiki/Representational_State_Transfer. Read more about the RESTful approach in "Stefan Tilkov's articles":http://www.infoq.com/articles/rest-introduction. Sometimes there are exceptions to this rule and those are discussed below. The _setting part_ is easy. You can set the locale in a +before_filter+ in the +ApplicationController+ like this: -- cgit v1.2.3 From 888383e0accf376109f29020c7f8cfbaa39338b9 Mon Sep 17 00:00:00 2001 From: Ayrton De Craene Date: Mon, 14 May 2012 14:04:24 +0200 Subject: 'Netherlands locale' does not make any sense, it's Dutch locale [ci skip] --- guides/source/i18n.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'guides/source') diff --git a/guides/source/i18n.textile b/guides/source/i18n.textile index a9da843d04..ee7176a6c8 100644 --- a/guides/source/i18n.textile +++ b/guides/source/i18n.textile @@ -220,7 +220,7 @@ Every helper method dependent on +url_for+ (e.g. helpers for named routes like + You may be satisfied with this. It does impact the readability of URLs, though, when the locale "hangs" at the end of every URL in your application. Moreover, from the architectural standpoint, locale is usually hierarchically above the other parts of the application domain: and URLs should reflect this. -You probably want URLs to look like this: +www.example.com/en/books+ (which loads the English locale) and +www.example.com/nl/books+ (which loads the Netherlands locale). This is achievable with the "over-riding +default_url_options+" strategy from above: you just have to set up your routes with "+path_prefix+":http://api.rubyonrails.org/classes/ActionController/Resources.html#M000354 option in this way: +You probably want URLs to look like this: +www.example.com/en/books+ (which loads the English locale) and +www.example.com/nl/books+ (which loads the Dutch locale). This is achievable with the "over-riding +default_url_options+" strategy from above: you just have to set up your routes with "+path_prefix+":http://api.rubyonrails.org/classes/ActionController/Resources.html#M000354 option in this way: # config/routes.rb @@ -229,7 +229,7 @@ scope "/:locale" do end -Now, when you call the +books_path+ method you should get +"/en/books"+ (for the default locale). An URL like +http://localhost:3001/nl/books+ should load the Netherlands locale, then, and following calls to +books_path+ should return +"/nl/books"+ (because the locale changed). +Now, when you call the +books_path+ method you should get +"/en/books"+ (for the default locale). An URL like +http://localhost:3001/nl/books+ should load the Dutch locale, then, and following calls to +books_path+ should return +"/nl/books"+ (because the locale changed). If you don't want to force the use of a locale in your routes you can use an optional path scope (denoted by the parentheses) like so: -- cgit v1.2.3 From 151aa9abae131f1a03513f756aeaef2fc403f9bb Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Mon, 14 May 2012 21:49:42 +0300 Subject: remove docs on Range#step --- guides/source/active_support_core_extensions.textile | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'guides/source') diff --git a/guides/source/active_support_core_extensions.textile b/guides/source/active_support_core_extensions.textile index 8045316e98..bf30ed64c8 100644 --- a/guides/source/active_support_core_extensions.textile +++ b/guides/source/active_support_core_extensions.textile @@ -2767,18 +2767,6 @@ As the example depicts, the +:db+ format generates a +BETWEEN+ SQL clause. That NOTE: Defined in +active_support/core_ext/range/conversions.rb+. -h4. +step+ - -Active Support extends the method +Range#step+ so that it can be invoked without a block: - - -(1..10).step(2) # => [1, 3, 5, 7, 9] - - -As the example shows, in that case the method returns an array with the corresponding elements. - -NOTE: Defined in +active_support/core_ext/range/blockless_step.rb+. - h4. +include?+ The methods +Range#include?+ and +Range#===+ say whether some value falls between the ends of a given instance: -- cgit v1.2.3