Module: UnbackedDomId

Included in:
GoogleMap::GeoXml, GoogleMap::Map, GoogleMap::Polyline
Defined in:
lib/unbacked_dom_id.rb

Overview

UnbackedDomId

Instance Method Summary collapse

Instance Method Details

#dom_id(prefix = nil) ⇒ Object

Implementation of codefluency.com/articles/2006/05/30/rails-views-dom-id-scheme

my_special_race_car.dom_id
=> "race_car_1"

another_race_car.dom_id
=> "race_car_2"


12
13
14
15
16
17
18
19
20
21
# File 'lib/unbacked_dom_id.rb', line 12

def dom_id(prefix=nil)
  id = self.object_id.to_s.gsub('-', '_')
  class_name = self.class.name.gsub(/::/, '/').
               gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
               gsub(/([a-z\d])([A-Z])/,'\1_\2').
               tr("-", "_").
               downcase
  prefix = prefix.nil? ? class_name : "#{prefix}_#{class_name}"
  "#{prefix}_#{id}"
end