Stephen
2009-Sep-18 15:05 UTC
[PATCH] Improve id creation for form tags when index specified
https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3226-form_for-for-new-objects-with-index-set#ticket-3226-2 I was using form_for to create multiple objects on the same page. All of them were of the same active record class. Even tho I was using index on the form_for, it created several form blocks with the same id new_object_class. This patch adds the _#{index} to the id name if an index is specified.. Examples and patch are in the lighthouse ticket and includes the appropriate test case. Best Regards, Stephen Blackstone --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Jason King
2009-Sep-18 16:42 UTC
Re: [PATCH] Improve id creation for form tags when index specified
Ok, this is bizarre timing. I was thinking about this problem last night, and I "dream-coded" that I suffixed ALL id fields with: (object.respond_to?(:to_param) and ( _id = object.to_param ) ? "_#{_id}" : "" ) I wonder if there''s room in your patch for something feeding automatically from the object? As well as having the explicit option with the :index value, perhaps you could also accept :index => true and use .to_param of the object in question in that case? Jason On Sep 18, 2009, at 8:05 AM, Stephen wrote:> https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3226-form_for-for-new-objects-with-index-set > #ticket-3226-2 > > I was using form_for to create multiple objects on the same page. > All of them were of the same active record class. Even tho I was > using index on the form_for, it created several form blocks with the > same id new_object_class. This patch adds the _#{index} to the id > name if an index is specified.. > > Examples and patch are in the lighthouse ticket and includes the > appropriate test case. > > > Best Regards, > Stephen Blackstone > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Stephen
2009-Sep-21 21:31 UTC
Re: [PATCH] Improve id creation for form tags when index specified
I''m not sure about passing :index => true since form_for passes along the value of index to fields_for... It seems like this is already the case for forms when the object is not a new object, i.e. form_for(@user) ..... etc yields <form action="/users/1" class="edit_user" id="edit_user_1" the only case where we seem to end up with an ambiguous form tag is multiple forms to create the same object type.. or am I missing something? Stephen Blackstone On Fri, Sep 18, 2009 at 12:42 PM, Jason King <smathy.werp@gmail.com> wrote:> Ok, this is bizarre timing. I was thinking about this problem last night, > and I *"dream-coded"* that I suffixed ALL id fields with: *(object.respond_to?(:to_param) > and ( _id = object.to_param ) ? "_#{_id}" : "" )* > I wonder if there''s room in your patch for something feeding automatically > from the object? As well as having the explicit option with the *:index*value, perhaps you could also accept > *:index => true* and use *.to_param* of the object in question in that > case? > > Jason > > On Sep 18, 2009, at 8:05 AM, Stephen wrote: > > > https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3226-form_for-for-new-objects-with-index-set#ticket-3226-2 > > I was using form_for to create multiple objects on the same page. All of > them were of the same active record class. Even tho I was using index on the > form_for, it created several form blocks with the same id > new_object_class. This patch adds the _#{index} to the id name if an > index is specified.. > > Examples and patch are in the lighthouse ticket and includes the > appropriate test case. > > > Best Regards, > Stephen Blackstone > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Jason King
2009-Sep-21 23:19 UTC
Re: [PATCH] Improve id creation for form tags when index specified
Yes, of course, you''re right. I had been thinking of the edit scenario in fields_for (which I think would be cool if it did what I suggested when passed true). The excitement of the coincidence confused me, and I didn''t really read properly that you were talking about new objects. +1 on your patch. It makes sense to be consistent between that <form> and what is already done in <input> tags. On Sep 21, 2009, at 2:31 PM, Stephen wrote:> I''m not sure about passing :index => true since form_for passes > along the value of index to fields_for... > > It seems like this is already the case for forms when the object is > not a new object, i.e. > > form_for(@user) ..... etc > > yields > <form action="/users/1" class="edit_user" id="edit_user_1" > the only case where we seem to end up with an ambiguous form tag is > multiple forms to create the same object type.. or am I missing > something? > > > Stephen Blackstone > > > On Fri, Sep 18, 2009 at 12:42 PM, Jason King <smathy.werp@gmail.com> > wrote: > Ok, this is bizarre timing. I was thinking about this problem last > night, and I "dream-coded" that I suffixed ALL id fields with: > (object.respond_to?(:to_param) and ( _id = object.to_param ) ? > "_#{_id}" : "" ) > > I wonder if there''s room in your patch for something feeding > automatically from the object? As well as having the explicit > option with the :index value, perhaps you could also accept :index > => true and use .to_param of the object in question in that case? > > Jason > > On Sep 18, 2009, at 8:05 AM, Stephen wrote: > >> https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3226-form_for-for-new-objects-with-index-set >> #ticket-3226-2 >> >> I was using form_for to create multiple objects on the same page. >> All of them were of the same active record class. Even tho I was >> using index on the form_for, it created several form blocks with >> the same id new_object_class. This patch adds the _#{index} to >> the id name if an index is specified.. >> >> Examples and patch are in the lighthouse ticket and includes the >> appropriate test case. >> >> >> Best Regards, >> Stephen Blackstone >> >> >> >> > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---