aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails
diff options
context:
space:
mode:
authorDavid Lee <davidomundo@gmail.com>2011-05-06 14:03:55 -0700
committerDavid Lee <davidomundo@gmail.com>2012-02-22 08:47:10 -0800
commit002713c64568114f3754799acc0723ea0d442f7a (patch)
treebd01c3ded14a9a96b92fbb54b8e0da35a899e374 /railties/lib/rails
parent66b7eb19279820b6464ad2b9e3f2efadb08f2ff2 (diff)
downloadrails-002713c64568114f3754799acc0723ea0d442f7a.tar.gz
rails-002713c64568114f3754799acc0723ea0d442f7a.tar.bz2
rails-002713c64568114f3754799acc0723ea0d442f7a.zip
Add config.default_method_for_update to support PATCH
PATCH is the correct HTML verb to map to the #update action. The semantics for PATCH allows for partial updates, whereas PUT requires a complete replacement. Changes: * adds config.default_method_for_update you can set to :patch * optionally use PATCH instead of PUT in resource routes and forms * adds the #patch verb to routes to detect PATCH requests * adds #patch? to Request * changes documentation and comments to indicate support for PATCH This change maintains complete backwards compatibility by keeping :put as the default for config.default_method_for_update.
Diffstat (limited to 'railties/lib/rails')
-rw-r--r--railties/lib/rails/application/configuration.rb3
-rw-r--r--railties/lib/rails/generators/active_model.rb6
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/application.rb3
-rw-r--r--railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb4
4 files changed, 10 insertions, 6 deletions
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index 825ea985fc..0297c41274 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -11,7 +11,7 @@ module Rails
:force_ssl, :helpers_paths, :logger, :log_tags, :preload_frameworks,
:railties_order, :relative_url_root, :secret_token,
:serve_static_assets, :ssl_options, :static_cache_control, :session_options,
- :time_zone, :reload_classes_only_on_change
+ :time_zone, :reload_classes_only_on_change, :default_method_for_update
attr_writer :log_level
attr_reader :encoding
@@ -40,6 +40,7 @@ module Rails
@reload_classes_only_on_change = true
@file_watcher = ActiveSupport::FileUpdateChecker
@exceptions_app = nil
+ @default_method_for_update = :put
@assets = ActiveSupport::OrderedOptions.new
@assets.enabled = false
diff --git a/railties/lib/rails/generators/active_model.rb b/railties/lib/rails/generators/active_model.rb
index 4b828340d2..f51028b657 100644
--- a/railties/lib/rails/generators/active_model.rb
+++ b/railties/lib/rails/generators/active_model.rb
@@ -37,7 +37,7 @@ module Rails
# GET show
# GET edit
- # PUT update
+ # PUT/PATCH update
# DELETE destroy
def self.find(klass, params=nil)
"#{klass}.find(#{params})"
@@ -58,13 +58,13 @@ module Rails
"#{name}.save"
end
- # PUT update
+ # PUT/PATCH update
def update_attributes(params=nil)
"#{name}.update_attributes(#{params})"
end
# POST create
- # PUT update
+ # PUT/PATCH update
def errors
"#{name}.errors"
end
diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb
index acf47a03e5..c970c2cf44 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/application.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb
@@ -31,6 +31,9 @@ module <%= app_const_base %>
# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
+ # Use PATCH as default method for update actions
+ # config.default_method_for_update = :patch
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
diff --git a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb
index 4ff15fd288..566d78c6eb 100644
--- a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb
+++ b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb
@@ -54,8 +54,8 @@ class <%= controller_class_name %>Controller < ApplicationController
end
end
- # PUT <%= route_url %>/1
- # PUT <%= route_url %>/1.json
+ # PUT/PATCH <%= route_url %>/1
+ # PUT/PATCH <%= route_url %>/1.json
def update
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>