This project is archived and is in readonly mode.
form_for doesn't work wit
Reported by Zach Dennis | October 27th, 2008 @ 02:33 PM | in 3.x
form_for doesn't work with an array of resources. For example, the following doesn't work right now in Rails:
<% form_for [expense.expense_reimbursement, expense] do |form| -%>
...
<% end %>
Below is the patch. I do not have the time to submit a proper patch, so in case someone has the time here's the fix and the ticket.
diff --git a/vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb b/vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb
index 7bb82ba..8ca9e68 100644
--- a/vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb
@@ -237,6 +237,13 @@ module ActionView
case record_or_name_or_array
when String, Symbol
object_name = record_or_name_or_array
+ object = nil
+ if args.first.is_a?(Array)
+ object = args.first.last
+ elsif args.first && !args.first.is_a?(Hash)
+ object = args.first
+ end
+ apply_form_for_options!(object, options) if object
when Array
object = record_or_name_or_array.last
object_name = ActionController::RecordIdentifier.singular_class_name(object)
Comments and changes to this ticket
-
Pratik March 10th, 2009 @ 12:32 PM
- Assigned user set to Pratik
- State changed from new to incomplete
-
Prem Sichanugrist (sikachu) January 20th, 2010 @ 06:16 PM
- State changed from incomplete to stale
-
Rizwan Reza January 21st, 2010 @ 04:18 PM
- State changed from stale to invalid
It's not valid to give an array in form_for.
-
Zach Dennis January 21st, 2010 @ 06:08 PM
According to its API is most certainly can:
form_for(record_or_name_or_array, *args, &proc)
Also, it can accept arrays where everything leading up the last element is a symbol:
<% form_for([:admin, @post]) do |f| %> ... <% end %>
The suggestion of the this ticket was to make it so you could say:
<% form_for([@admin, @post]) do |f| %> ... <% end %>
This made form_for more flexible and didn't require you know in advance the specific type of resource (or its path) in the partial. It could be determined at run-time.
As something changed recently in Rails which got rid of passing in arrays in form_for?
-
Rizwan Reza January 25th, 2010 @ 12:42 AM
- State changed from invalid to open
Can you make a patch of what you're proposing? Thanks!
http://rails.lighthouseapp.com/projects/8994/sending-patches
-
Dan Pickett May 9th, 2010 @ 06:03 PM
- Tag changed from actionview, form_for to actionview, bugmash, form_for
-
Ryan Bigg May 14th, 2010 @ 12:56 AM
This ticket is 2 years old and I don't think it's valid any more.
-
Christopher Redinger May 14th, 2010 @ 06:30 PM
Zach,
Can you provide a little more clarity on what this should do. Specifically, what does @admin provide in the example you cited?
-
Zach Dennis May 14th, 2010 @ 07:09 PM
Christopher, read my comment on this ticket from January 21st, 2010. Let me know if that is not clear for you.
Ryan, I think it's still valid. :)
Everyone... there doesn't seem to be any disagreements with the proposed functionality, just a proper patch. Is this accurate? If so, since no one has taken my offer for making the patch, I will shoot to make one in the next week or so, maybe sooner!
-
Dan Pickett May 15th, 2010 @ 02:58 AM
I'm +1 on this - if polymorphic_url/path supports an array of objects form_for should as well. If I have time this weekend I'll see if I can craft a patch
Christopher (and Zach correct me if I'm wrong) I think the intent is for the above example to do a PUT on reimbursement_expense_path(expense.expense_reimbursement, expense)
-
Anil Wadghule May 15th, 2010 @ 08:37 AM
This issue looks like non-existent now. Check rails app attached.
-
Rizwan Reza May 15th, 2010 @ 10:06 AM
- State changed from open to resolved
Please let me know if it needs to be reopened.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>