diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-06-30 12:16:17 -0700 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-06-30 12:16:17 -0700 |
commit | 49d069d797790bdfcce592f45e3cdb5d5cac3a55 (patch) | |
tree | 93f40504cf23d088c2dd717d65c3d7ed4348cc06 /actionpack/lib/action_controller | |
parent | 4d9be13a381948377678f12880a43341ea0571dc (diff) | |
parent | 166dbaa7526a96fdf046f093f25b0a134b277a68 (diff) | |
download | rails-49d069d797790bdfcce592f45e3cdb5d5cac3a55.tar.gz rails-49d069d797790bdfcce592f45e3cdb5d5cac3a55.tar.bz2 rails-49d069d797790bdfcce592f45e3cdb5d5cac3a55.zip |
Merge pull request #6904 from guilleiguaran/remove-amo-dependency-in-ap
Remove Active Model dependency from Action Pack
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r-- | actionpack/lib/action_controller/model_naming.rb | 12 | ||||
-rw-r--r-- | actionpack/lib/action_controller/record_identifier.rb | 8 |
2 files changed, 17 insertions, 3 deletions
diff --git a/actionpack/lib/action_controller/model_naming.rb b/actionpack/lib/action_controller/model_naming.rb new file mode 100644 index 0000000000..785221dc3d --- /dev/null +++ b/actionpack/lib/action_controller/model_naming.rb @@ -0,0 +1,12 @@ +module ActionController + 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_controller/record_identifier.rb b/actionpack/lib/action_controller/record_identifier.rb index 16a5decc62..d3ac406618 100644 --- a/actionpack/lib/action_controller/record_identifier.rb +++ b/actionpack/lib/action_controller/record_identifier.rb @@ -1,4 +1,5 @@ require 'active_support/core_ext/module' +require 'action_controller/model_naming' module ActionController # The record identifier encapsulates a number of naming conventions for dealing with records, like Active Records or @@ -27,6 +28,8 @@ module ActionController module RecordIdentifier extend self + include ModelNaming + JOIN = '_'.freeze NEW = 'new'.freeze @@ -40,7 +43,7 @@ module ActionController # dom_class(post, :edit) # => "edit_post" # dom_class(Person, :edit) # => "edit_person" def dom_class(record_or_class, prefix = nil) - singular = ActiveModel::Naming.param_key(record_or_class) + singular = model_name_from_record_or_class(record_or_class).param_key prefix ? "#{prefix}#{JOIN}#{singular}" : singular end @@ -73,8 +76,7 @@ module ActionController # method that replaces all characters that are invalid inside DOM ids, with valid ones. You need to # make sure yourself that your dom ids are valid, in case you overwrite this method. def record_key_for_dom_id(record) - record = record.to_model if record.respond_to?(:to_model) - key = record.to_key + key = convert_to_model(record).to_key key ? key.join('_') : key end end |