Sha256: 02ca91f345ab03347b72b30eaf31242a9fb21d25a477ba62b61498165b6ac752
Contents?: true
Size: 663 Bytes
Versions: 12
Compression:
Stored size: 663 Bytes
Contents
module DidYouMean class SimilarAttributeFinder include BaseFinder attr_reader :columns, :attribute_name def initialize(exception) @columns = exception.frame_binding.eval("self.class").columns @attribute_name = (/unknown attribute(: | ')(\w+)/ =~ exception.original_message) && $2 end def words columns.map(&:name) end alias target_word attribute_name def format(column_name) "%{column}: %{type}" % { column: column_name, type: columns.detect{|c| c.name == column_name }.type } end end finders["ActiveRecord::UnknownAttributeError"] = SimilarAttributeFinder end
Version data entries
12 entries across 12 versions & 1 rubygems