Permalink
Browse files

Merge pull request #775 from dnagir/rescue-content_columns

Performance degradation in content_columns: respond_to instead of rescue
  • Loading branch information...
2 parents 0039835 + 8dda9f8 commit cae97bf0105346231f8b6c018164e9f3e19c079b @justinfrench committed Jan 14, 2012
Showing with 6 additions and 2 deletions.
  1. +1 −0 .gitignore
  2. +5 −2 lib/formtastic/helpers/inputs_helper.rb
View
@@ -4,6 +4,7 @@ coverage
coverage.data
pkg
*~
+*.swp
*watchr.rb
log/*
.rvmrc
@@ -351,7 +351,10 @@ def association_columns(*by_associations) #:nodoc:
# Collects content columns (non-relation columns) for the current form object class.
def content_columns #:nodoc:
- model_name.constantize.content_columns.collect { |c| c.name.to_sym }.compact rescue []
+ # TODO: NameError is raised by Inflector.constantize. Consider checking if it exists instead.
+ begin klass = model_name.constantize; rescue NameError; return [] end
+ return [] unless klass.respond_to?(:content_columns)
+ klass.content_columns.collect { |c| c.name.to_sym }.compact
end
# Deals with :for option when it's supplied to inputs methods. Additional
@@ -397,4 +400,4 @@ def field_set_title_from_args(*args) #:nodoc:
end
end
-end
+end

0 comments on commit cae97bf

Please sign in to comment.