Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #3196 (closed enhancement: undocumented)

Opened 2 years ago

Last modified 1 year ago

[PATCH] Multiple Associations for Forms / ActiveRecord

Reported by: benanderson.us@gmail.com Assigned to: anonymous
Priority: normal Milestone: 1.2.3
Component: ActiveRecord Version: 0.14.4.
Severity: normal Keywords: verified
Cc: justin@aspect.net, bitsweat

Description (Last modified by bitsweat)

In an effort to keep rails' seamless integration between html forms and persistent objects, I thought this feature could be used (I'm currently using it in my application). It lets you udpate multiple associations in a form. Probably the best way is to explain through potential user code. Here's from my app: in rhtml:

  <% for @event in @events %>
    <% for @article in @event.articles %>
      <%= text_field("event[]article[]", 'id') %>

now I can load the user's input back into the db upon form submission. This is from my action:

  @events = Event.load_hash(params[:event])

Simple as pie. This is my first rails(and ruby) patch submitted, so keep that in mind. Hopefully the submitted tests will help explain as well. I'll keep my eye on this thread, so let me know comments one way or the other. Thanks, Ben

Attachments

multiple_associations_for_forms.patch (13.1 kB) - added by benanderson.us@gmail.com on 12/12/05 22:13:57.

Change History

12/12/05 22:13:57 changed by benanderson.us@gmail.com

  • attachment multiple_associations_for_forms.patch added.

12/12/05 22:17:19 changed by benanderson.us@gmail.com

  • summary changed from Multiple Associations for Forms / ActiveRecord to [PATCH] Multiple Associations for Forms / ActiveRecord.

12/12/05 22:37:40 changed by anonymous

  • cc set to justin@aspect.net.

12/12/05 23:02:20 changed by bitsweat

  • cc changed from justin@aspect.net to justin@aspect.net, bitsweat.
  • version set to 0.14.4..
  • description changed.
  • milestone set to 1.1.

12/12/05 23:05:39 changed by bitsweat

Nice patch, Ben. Special thanks for test coverage!

The implementation of the load_hash method is very dense. Perhaps it could be refined (or commented?)

Also, lines 259-271 pull in an unrelated change.

12/13/05 12:34:10 changed by benanderson.us@gmail.com

  • owner changed from David to anonymous.
  • status changed from new to assigned.

Ok - let me clean it up a bit. I also just noticed when going back to my app (after having made some changes during the unit testing phase) things are broken. I was curious to get some feedback as to the likelihood of this patch actually making it into the trunk before I spent too much time polishing it up.

03/13/07 03:05:27 changed by josh

  • keywords set to verified.
  • status changed from assigned to closed.
  • resolution set to undocumented.

As suggested by bitsweat, it still needs some documentation.