Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 8ca17926dc747f1808cf13cf89dea0ab11ffbccf 1 parent 2646240
Piotr Sarnacki drogus authored
6 actionpack/lib/action_view/helpers/form_helper.rb
View
@@ -4,12 +4,12 @@
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 FormHelper
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 @@ def default_form_builder
end
class FormBuilder
- include ActionController::ModelNaming
+ include ModelNaming
# The methods which wrap a form helper call.
class_attribute :field_helpers
12 actionpack/lib/action_view/model_naming.rb
View
@@ -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
2  actionpack/lib/action_view/record_identifier.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.