aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/form_helper.rb
diff options
context:
space:
mode:
authorGuillermo Iguaran <guilleiguaran@gmail.com>2012-06-28 23:54:12 -0500
committerGuillermo Iguaran <guilleiguaran@gmail.com>2012-06-30 11:04:31 -0500
commit166dbaa7526a96fdf046f093f25b0a134b277a68 (patch)
tree665afc57ce1ddde3439c1f0296f1ca51e0b2fe05 /actionpack/lib/action_view/helpers/form_helper.rb
parent809bdf342638592b0dfd2f888c7c9a4ac093d8cf (diff)
downloadrails-166dbaa7526a96fdf046f093f25b0a134b277a68.tar.gz
rails-166dbaa7526a96fdf046f093f25b0a134b277a68.tar.bz2
rails-166dbaa7526a96fdf046f093f25b0a134b277a68.zip
Remove ActiveModel dependency from ActionPack
ActiveModel is used in ActionPack for ActiveModel::Naming for a few, mostly optional aspects of ActionPack related to automatically converting an ActiveModel compliant object into a key for params and routing. It uses only three methods of ActiveModel (ActiveModel::Naming.route_key, ActiveModel::Naming.singular_route_key and ActiveModel::Naming.param_key).
Diffstat (limited to 'actionpack/lib/action_view/helpers/form_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb21
1 files changed, 8 insertions, 13 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index ba2a26fd09..b34f6c8650 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -12,6 +12,7 @@ require 'active_support/core_ext/string/output_safety'
require 'active_support/core_ext/array/extract_options'
require 'active_support/deprecation'
require 'active_support/core_ext/string/inflections'
+require 'action_controller/model_naming'
module ActionView
# = Action View Form Helpers
@@ -117,11 +118,7 @@ module ActionView
include FormTagHelper
include UrlHelper
-
- # Converts the given object to an ActiveModel compliant one.
- def convert_to_model(object)
- object.respond_to?(:to_model) ? object.to_model : object
- end
+ include ActionController::ModelNaming
# Creates a form that allows the user to create or update the attributes
# of a specific model object.
@@ -411,7 +408,7 @@ module ActionView
object = nil
else
object = record.is_a?(Array) ? record.last : record
- object_name = options[:as] || ActiveModel::Naming.param_key(object)
+ object_name = options[:as] || model_name_from_record_or_class(object).param_key
apply_form_for_options!(record, object, options)
end
@@ -1128,7 +1125,7 @@ module ActionView
object_name = record_name
else
object = record_name
- object_name = ActiveModel::Naming.param_key(object)
+ object_name = model_name_from_record_or_class(object).param_key
end
builder = options[:builder] || default_form_builder
@@ -1142,9 +1139,11 @@ module ActionView
end
class FormBuilder
+ include ActionController::ModelNaming
+
# The methods which wrap a form helper call.
class_attribute :field_helpers
- self.field_helpers = FormHelper.instance_methods - [:form_for, :convert_to_model]
+ self.field_helpers = FormHelper.instance_methods - [:form_for, :convert_to_model, :model_name_from_record_or_class]
attr_accessor :object_name, :object, :options
@@ -1214,7 +1213,7 @@ module ActionView
end
else
record_object = record_name.is_a?(Array) ? record_name.last : record_name
- record_name = ActiveModel::Naming.param_key(record_object)
+ record_name = model_name_from_record_or_class(record_object).param_key
end
index = if options.has_key?(:index)
@@ -1396,10 +1395,6 @@ module ActionView
@nested_child_index[name] ||= -1
@nested_child_index[name] += 1
end
-
- def convert_to_model(object)
- object.respond_to?(:to_model) ? object.to_model : object
- end
end
end