Permalink
Browse files

Use ActiveModel::Naming#singular instead of ActionController::RecordI…

…dentifier#singular_class_name in Rails 3
  • Loading branch information...
1 parent e7e29b6 commit 44813410b6c9d948dd6f2d08356a2fec4b89e3c9 Mateusz Drożdżyński committed with yabawock Jul 22, 2010
Showing with 4 additions and 2 deletions.
  1. +4 −2 lib/formtastic.rb
View
@@ -1824,12 +1824,14 @@ def semantic_#{meth}(record_or_name_or_array, *args, &proc)
options[:builder] ||= @@builder
options[:html] ||= {}
+ singularizer = defined?(ActiveModel::Naming.singular) ? ActiveModel::Naming.method(:singular) : ActionController::RecordIdentifier.method(:singular_class_name)
+
class_names = options[:html][:class] ? options[:html][:class].split(" ") : []
class_names << "formtastic"
class_names << case record_or_name_or_array
when String, Symbol then record_or_name_or_array.to_s # :post => "post"
- when Array then ActionController::RecordIdentifier.singular_class_name(record_or_name_or_array.last.class) # [@post, @comment] # => "comment"
- else ActionController::RecordIdentifier.singular_class_name(record_or_name_or_array.class) # @post => "post"
+ when Array then singularizer.call(record_or_name_or_array.last.class) # [@post, @comment] # => "comment"
+ else singularizer.call(record_or_name_or_array.class) # @post => "post"
end
options[:html][:class] = class_names.join(" ")

0 comments on commit 4481341

Please sign in to comment.