aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2012-08-15 18:44:18 +0200
committerPiotr Sarnacki <drogus@gmail.com>2012-08-28 10:51:03 +0200
commit8ca17926dc747f1808cf13cf89dea0ab11ffbccf (patch)
treef6d66396327a5a758fce5cbcecbbb225062e4a1f /actionpack/lib/action_view
parent264624049ea02a76a84e88023f611820bfdde9eb (diff)
downloadrails-8ca17926dc747f1808cf13cf89dea0ab11ffbccf.tar.gz
rails-8ca17926dc747f1808cf13cf89dea0ab11ffbccf.tar.bz2
rails-8ca17926dc747f1808cf13cf89dea0ab11ffbccf.zip
Add ActionView::ModelNaming
It's just a duplicate of ActionController::ModelNaming. These are just a simple helpers for decoupling Active Model, so it does not make sense to extract it to Active Support, but the point is to decouple also Action View and Action Pack
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb6
-rw-r--r--actionpack/lib/action_view/model_naming.rb12
-rw-r--r--actionpack/lib/action_view/record_identifier.rb2
3 files changed, 16 insertions, 4 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index b79577bcd3..17fe7dc1b4 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -4,12 +4,12 @@ require 'action_view/helpers/tag_helper'
require 'action_view/helpers/form_tag_helper'
require 'action_view/helpers/active_model_helper'
require 'action_view/helpers/tags'
+require 'action_view/model_naming'
require 'active_support/core_ext/class/attribute_accessors'
require 'active_support/core_ext/hash/slice'
require 'active_support/core_ext/string/output_safety'
require 'active_support/core_ext/array/extract_options'
require 'active_support/core_ext/string/inflections'
-require 'action_controller/model_naming'
module ActionView
# = Action View Form Helpers
@@ -115,7 +115,7 @@ module ActionView
include FormTagHelper
include UrlHelper
- include ActionController::ModelNaming
+ include ModelNaming
# Creates a form that allows the user to create or update the attributes
# of a specific model object.
@@ -1156,7 +1156,7 @@ module ActionView
end
class FormBuilder
- include ActionController::ModelNaming
+ include ModelNaming
# The methods which wrap a form helper call.
class_attribute :field_helpers
diff --git a/actionpack/lib/action_view/model_naming.rb b/actionpack/lib/action_view/model_naming.rb
new file mode 100644
index 0000000000..e09ebd60df
--- /dev/null
+++ b/actionpack/lib/action_view/model_naming.rb
@@ -0,0 +1,12 @@
+module ActionView
+ module ModelNaming
+ # Converts the given object to an ActiveModel compliant one.
+ def convert_to_model(object)
+ object.respond_to?(:to_model) ? object.to_model : object
+ end
+
+ def model_name_from_record_or_class(record_or_class)
+ (record_or_class.is_a?(Class) ? record_or_class : convert_to_model(record_or_class).class).model_name
+ end
+ end
+end
diff --git a/actionpack/lib/action_view/record_identifier.rb b/actionpack/lib/action_view/record_identifier.rb
index 0f4fc8aa75..0d44145231 100644
--- a/actionpack/lib/action_view/record_identifier.rb
+++ b/actionpack/lib/action_view/record_identifier.rb
@@ -1,5 +1,5 @@
require 'active_support/core_ext/module'
-require 'action_controller/model_naming'
+require 'action_view/model_naming'
module ActionView
# The record identifier encapsulates a number of naming conventions for dealing with records, like Active Records or