Module: DomId

Defined in:
lib/dom_id.rb

Constant Summary collapse

VERSION =
'0.1.0'

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

comment.dom_id
=> "comment_15"

Use in views and controllers instead of doing “comment_<%= comment.id %>”



14
15
16
17
18
# File 'lib/dom_id.rb', line 14

def dom_id(prefix=nil)
  display_id = new_record? ? "new" : id
  prefix = prefix.nil? ? self.class.name.underscore : "#{prefix}_#{self.class.name.underscore}"
  "#{prefix}_#{display_id}"
end