From 7a2be37592a13aaf557619336a54da9092950b18 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 10 Nov 2010 19:12:10 -0200 Subject: Remove copy_instance_variables_from from guides --- .../source/active_support_core_extensions.textile | 33 ---------------------- .../source/api_documentation_guidelines.textile | 12 -------- 2 files changed, 45 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 9b1d264d2c..8c11b2a11a 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -395,39 +395,6 @@ C.new(0, 1).instance_values # => {"x" => 0, "y" => 1} NOTE: Defined in +active_support/core_ext/object/instance_variables.rb+. -h5. +copy_instance_variables_from(object, exclude = [])+ - -Copies the instance variables of +object+ into +self+. - -Instance variable names in the +exclude+ array are ignored. If +object+ -responds to +protected_instance_variables+ the ones returned are -also ignored. For example, Rails controllers implement that method. - -In both arrays strings and symbols are understood, and they have to include -the at sign. - - -class C - def initialize(x, y, z) - @x, @y, @z = x, y, z - end - - def protected_instance_variables - %w(@z) - end -end - -a = C.new(0, 1, 2) -b = C.new(3, 4, 5) - -a.copy_instance_variables_from(b, [:@y]) -# a is now: @x = 3, @y = 1, @z = 2 - - -In the example +object+ and +self+ are of the same type, but they don't need to. - -NOTE: Defined in +active_support/core_ext/object/instance_variables.rb+. - h4. Silencing Warnings, Streams, and Exceptions The methods +silence_warnings+ and +enable_warnings+ change the value of +$VERBOSE+ accordingly for the duration of their block, and reset it afterwards: diff --git a/railties/guides/source/api_documentation_guidelines.textile b/railties/guides/source/api_documentation_guidelines.textile index 900b3fb5d5..523fbd8a77 100644 --- a/railties/guides/source/api_documentation_guidelines.textile +++ b/railties/guides/source/api_documentation_guidelines.textile @@ -115,18 +115,6 @@ Use fixed-width fonts for: * method parameters * file names - -# Copies the instance variables of +object+ into +self+. -# -# Instance variable names in the +exclude+ array are ignored. If +object+ -# responds to protected_instance_variables the ones returned are -# also ignored. For example, Rails controllers implement that method. -# ... -def copy_instance_variables_from(object, exclude = []) - ... -end - - WARNING: Using a pair of ++...++ for fixed-width font only works with *words*; that is: anything matching \A\w+\z. For anything else use +<tt>...</tt>+, notably symbols, setters, inline snippets, etc: h4. Regular Font -- cgit v1.2.3 From c577e90f61b060164589e7112838e461c42bfe29 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 10 Nov 2010 23:46:00 +0100 Subject: restores the example for fixed-width font in API guidelines --- railties/guides/source/api_documentation_guidelines.textile | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'railties/guides/source') diff --git a/railties/guides/source/api_documentation_guidelines.textile b/railties/guides/source/api_documentation_guidelines.textile index 523fbd8a77..e3ccd6396c 100644 --- a/railties/guides/source/api_documentation_guidelines.textile +++ b/railties/guides/source/api_documentation_guidelines.textile @@ -115,6 +115,16 @@ Use fixed-width fonts for: * method parameters * file names + +class Array + # Calls to_param on all its elements and joins the result with + # slashes. This is used by url_for in Action Pack. + def to_param + collect { |e| e.to_param }.join '/' + end +end + + WARNING: Using a pair of ++...++ for fixed-width font only works with *words*; that is: anything matching \A\w+\z. For anything else use +<tt>...</tt>+, notably symbols, setters, inline snippets, etc: h4. Regular Font -- cgit v1.2.3 From d44cd370bfd044d460359ec8c2bb5ce36451d341 Mon Sep 17 00:00:00 2001 From: Paco Guzman Date: Sat, 13 Nov 2010 12:17:21 +0100 Subject: colorize_logging is a Rails General Configuration option not a specific option of ActiveRecord --- railties/guides/source/configuring.textile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index bb38c64307..28fff5c11e 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -32,7 +32,7 @@ config.filter_parameters << :password This is a setting for Rails itself. If you want to pass settings to individual Rails components, you can do so via the same +config+ object: -config.active_record.colorize_logging = false +config.active_record.timestamped_migrations = false Rails will use that particular setting to configure Active Record. @@ -45,6 +45,8 @@ h4. Rails General Configuration * +config.cache_store+ configures which cache store to use for Rails caching. Options include +:memory_store+, +:file_store+, +:mem_cache_store+ or the name of your own custom class. +* +config.colorize_logging+ (true by default) specifies whether or not to use ANSI color codes when logging information. + * +config.controller_paths+ accepts an array of paths that will be searched for controllers. Defaults to +app/controllers+. * +config.database_configuration_file+ overrides the default path for the database configuration file. Default to +config/database.yml+. @@ -105,8 +107,6 @@ h4. Configuring Active Record * +config.active_record.pluralize_table_names+ specifies whether Rails will look for singular or plural table names in the database. If set to +true+ (the default), then the Customer class will use the +customers+ table. If set to +false+, then the Customers class will use the +customer+ table. -* +config.active_record.colorize_logging+ (true by default) specifies whether or not to use ANSI color codes when logging information from ActiveRecord. - * +config.active_record.default_timezone+ determines whether to use +Time.local+ (if set to +:local+) or +Time.utc+ (if set to +:utc+) when pulling dates and times from the database. The default is +:local+. * +config.active_record.schema_format+ controls the format for dumping the database schema to a file. The options are +:ruby+ (the default) for a database-independent version that depends on migrations, or +:sql+ for a set of (potentially database-dependent) SQL statements. -- cgit v1.2.3 From 7e1f6688e92c18f9973ad65db7b95de495b98947 Mon Sep 17 00:00:00 2001 From: Rajinder Yadav Date: Sat, 13 Nov 2010 20:24:04 -0500 Subject: the partial option is not required for simple partial rendering --- railties/guides/source/layouts_and_rendering.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile index c65ea5c797..4e26d152bf 100644 --- a/railties/guides/source/layouts_and_rendering.textile +++ b/railties/guides/source/layouts_and_rendering.textile @@ -970,7 +970,7 @@ Partial templates - usually just called "partials" - are another device for brea h5. Naming Partials -To render a partial as part of a view, you use the +render+ method within the view, and include the +:partial+ option: +To render a partial as part of a view, you use the +render+ method within the view: <%= render "menu" %> -- cgit v1.2.3 From 23f71c431dae9ec389a861700ea84c7b0cbf913c Mon Sep 17 00:00:00 2001 From: Rajinder Yadav Date: Sun, 14 Nov 2010 05:12:01 -0500 Subject: corrected sample code to clear @_current_user class variable also --- railties/guides/source/action_controller_overview.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/action_controller_overview.textile b/railties/guides/source/action_controller_overview.textile index c02e9f1912..3774c7fcf5 100644 --- a/railties/guides/source/action_controller_overview.textile +++ b/railties/guides/source/action_controller_overview.textile @@ -239,7 +239,7 @@ class LoginsController < ApplicationController # "Delete" a login, aka "log the user out" def destroy # Remove the user id from the session - session[:current_user_id] = nil + @_current_user = session[:current_user_id] = nil redirect_to root_url end end -- cgit v1.2.3 From f69784289b6efd0eabb674d6467b2cd0c0a4af07 Mon Sep 17 00:00:00 2001 From: Rajinder Yadav Date: Sun, 14 Nov 2010 05:20:10 -0500 Subject: added note with example for using flash in redirection --- railties/guides/source/action_controller_overview.textile | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'railties/guides/source') diff --git a/railties/guides/source/action_controller_overview.textile b/railties/guides/source/action_controller_overview.textile index 3774c7fcf5..cabc0c8a7f 100644 --- a/railties/guides/source/action_controller_overview.textile +++ b/railties/guides/source/action_controller_overview.textile @@ -261,6 +261,13 @@ class LoginsController < ApplicationController end +Note it is also possible to assign a flash message as part of the redirection. + + + redirect_to root_url, :notice => "You have successfully logged out" + + + The +destroy+ action redirects to the application's +root_url+, where the message will be displayed. Note that it's entirely up to the next action to decide what, if anything, it will do with what the previous action put in the flash. It's conventional to display eventual errors or notices from the flash in the application's layout: -- cgit v1.2.3 From abf225423cbe11fcb0460a40bd49263694eaef06 Mon Sep 17 00:00:00 2001 From: Rajinder Yadav Date: Sun, 14 Nov 2010 06:02:16 -0500 Subject: removed unnecessary indentation --- railties/guides/source/action_controller_overview.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/action_controller_overview.textile b/railties/guides/source/action_controller_overview.textile index cabc0c8a7f..b39075f101 100644 --- a/railties/guides/source/action_controller_overview.textile +++ b/railties/guides/source/action_controller_overview.textile @@ -264,7 +264,7 @@ end Note it is also possible to assign a flash message as part of the redirection. - redirect_to root_url, :notice => "You have successfully logged out" +redirect_to root_url, :notice => "You have successfully logged out" -- cgit v1.2.3 From 330d65d31222148019855d6914e35c8cd9f90cd5 Mon Sep 17 00:00:00 2001 From: Aditya Sanghi Date: Sun, 14 Nov 2010 18:27:08 +0530 Subject: deliver_* is no more --- railties/guides/source/action_mailer_basics.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile index 41738827b2..8d2ce44e93 100644 --- a/railties/guides/source/action_mailer_basics.textile +++ b/railties/guides/source/action_mailer_basics.textile @@ -446,7 +446,7 @@ The following configuration options are best made in one of the environment file |sendmail_settings|Allows you to override options for the :sendmail delivery method.
  • :location - The location of the sendmail executable. Defaults to /usr/sbin/sendmail.
  • :arguments - The command line arguments to be passed to sendmail. Defaults to -i -t.
| |raise_delivery_errors|Whether or not errors should be raised if the email fails to be delivered.| |delivery_method|Defines a delivery method. Possible values are :smtp (default), :sendmail, :file and :test.| -|perform_deliveries|Determines whether deliver_* methods are actually carried out. By default they are, but this can be turned off to help functional testing.| +|perform_deliveries|Determines whether deliveries are actually carried out when the +deliver+ method is invoked on the Mail message. By default they are, but this can be turned off to help functional testing.| |deliveries|Keeps an array of all the emails sent out through the Action Mailer with delivery_method :test. Most useful for unit and functional testing.| h4. Example Action Mailer Configuration -- cgit v1.2.3 From fae4264a7efe2df4890b5f1095bd7454e3bcb939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 14 Nov 2010 16:22:21 +0100 Subject: Update the guides. --- railties/guides/source/active_support_core_extensions.textile | 6 ++++++ 1 file changed, 6 insertions(+) (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 8c11b2a11a..dc1200812e 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -167,6 +167,12 @@ def log_info(sql, name, ms) end
++try+ can also be called without arguments but a block, which will only be executed if the object is not nil: + + +@person.try { |p| "#{p.first_name} #{p.last_name}" } + + NOTE: Defined in +active_support/core_ext/object/try.rb+. h4. +singleton_class+ -- cgit v1.2.3 From c996901913d74640afb1856044e5a5d6bd12a7fd Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 14 Nov 2010 21:00:26 -0200 Subject: Change deprecated syntax and use f.submit instead of submit_tag --- railties/guides/source/form_helpers.textile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile index 80e0421b48..35b9d486b9 100644 --- a/railties/guides/source/form_helpers.textile +++ b/railties/guides/source/form_helpers.textile @@ -232,13 +232,13 @@ The corresponding view +app/views/articles/new.html.erb+ using +form_for+ looks <%= form_for @article, :url => { :action => "create" }, :html => {:class => "nifty_form"} do |f| %> <%= f.text_field :title %> <%= f.text_area :body, :size => "60x12" %> - <%= submit_tag "Create" %> + <%= f.submit "Create" %> <% end %> There are a few things to note here: -# +:article+ is the name of the model and +@article+ is the actual object being edited. +# +@article+ is the actual object being edited. # There is a single hash of options. Routing options are passed in the +:url+ hash, HTML options are passed in the +:html+ hash. # The +form_for+ method yields a *form builder* object (the +f+ variable). # Methods to create form controls are called *on* the form builder object +f+ @@ -294,13 +294,13 @@ When dealing with RESTful resources, calls to +form_for+ can get significantly e ## Creating a new article # long-style: -form_for(:article, @article, :url => articles_path) +form_for(@article, :url => articles_path) # same thing, short-style (record identification gets used): form_for(@article) ## Editing an existing article # long-style: -form_for(:article, @article, :url => article_path(@article), :html => { :method => "put" }) +form_for(@article, :url => article_path(@article), :html => { :method => "put" }) # short-style: form_for(@article) -- cgit v1.2.3 From 324569bb113ab6525d3eb1d5e35fa6bc911917eb Mon Sep 17 00:00:00 2001 From: Jaime Iniesta Date: Mon, 15 Nov 2010 00:07:25 +0100 Subject: Getting Started guide: remove calls to f.error_messages as it has been removed from Rails --- railties/guides/source/getting_started.textile | 8 -------- 1 file changed, 8 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index e592417dcb..f3420e37d1 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -919,8 +919,6 @@ So first, we'll wire up the Post show template (+/app/views/posts/show.html.erb+

Add a comment:

<%= form_for([@post, @post.comments.build]) do |f| %> - <%= f.error_messages %> -
<%= f.label :commenter %>
<%= f.text_field :commenter %> @@ -989,8 +987,6 @@ Once we have made the new comment, we send the user back to the original post us

Add a comment:

<%= form_for([@post, @post.comments.build]) do |f| %> - <%= f.error_messages %> -
<%= f.label :commenter %>
<%= f.text_field :commenter %> @@ -1057,8 +1053,6 @@ Then in the +app/views/posts/show.html.erb+ you can change it to look like the f

Add a comment:

<%= form_for([@post, @post.comments.build]) do |f| %> - <%= f.error_messages %> -
<%= f.label :commenter %>
<%= f.text_field :commenter %> @@ -1086,8 +1080,6 @@ Lets also move that new comment section out to it's own partial, again, you crea <%= form_for([@post, @post.comments.build]) do |f| %> - <%= f.error_messages %> -
<%= f.label :commenter %>
<%= f.text_field :commenter %> -- cgit v1.2.3 From c2c2b8b96220b11eb3512b1eaaf7985c84f03d67 Mon Sep 17 00:00:00 2001 From: James Miller Date: Mon, 15 Nov 2010 09:26:57 -0700 Subject: Add HTTP Verb Constraints (:via) to routing guide --- railties/guides/source/routing.textile | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'railties/guides/source') diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile index f48ae9c7f7..cc0c3316c8 100644 --- a/railties/guides/source/routing.textile +++ b/railties/guides/source/routing.textile @@ -436,6 +436,26 @@ match 'exit' => 'sessions#destroy', :as => :logout This will create +logout_path+ and +logout_url+ as named helpers in your application. Calling +logout_path+ will return +/exit+ +h4. HTTP Verb Constraints + +You can use the +:via+ option to constrain the request to one or more HTTP methods: + + +match 'photos/show' => 'photos#show', :via => :get + + +There is a shorthand version of this as well: + + +get 'photos/show' + + +You can also permit more than one verb to a single route: + + +match 'photos/show' => 'photos#show', :via => [:get, :post] + + h4. Segment Constraints You can use the +:constraints+ option to enforce a format for a dynamic segment: -- cgit v1.2.3