Helper to generate element id?

Anyone know if there’s a helper to generate an element’s ID given
object,
method, id, and the other options taken by form helpers like text_field?

Thanks!
Daniel

Whoops! that should read:

Anyone know if there’s a helper to generate an element’s ID given
object,
method, INDEX, and the other options taken by form helpers like
text_field?

Daniel H. wrote:

Anyone know if there’s a helper to generate an element’s ID given object,
method, INDEX, and the other options taken by form helpers like text_field?

Yes, there’s add_default_name_and_id(options), but it’s private to
class ActionView::Helpers::InstanceTag. So if you want to define
your own AR form helper you have to do put something like this in lib:

class ActionView
class Base
def my_field(object_name, method, options = {})
Helpers::InstanceTag.new(object_name, method,
self).to_my_tag(self, options)
end

class Helpers::InstanceTag
def to_my_tag(template, options = {})
options = options.stringify_keys
add_default_name_and_id(options)

options[‘id’] # e.g., just return the id, per your question
end
end
end


We develop, watch us RoR, in numbers too big to ignore.