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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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? On Friday 03 November 2006 5:55 pm, Daniel Higginbotham wrote:> 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 > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Daniel Higginbotham 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---