This project is archived and is in readonly mode.

#1281 ✓resolved
Zach Dennis

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

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>

Attachments

Pages