This project is archived and is in readonly mode.
Add an option to omit the creation of hidden field with object id when using fields_for
Reported by wildchild | May 7th, 2010 @ 06:45 PM | in 3.x
Some so called "ORMs" (CouchRest for example) allow to create inline associations, in this case associated objects does not have its own IDs. An option to omit the creation of hidden field with associated object id would be useful.
Usage:
# Disable hidden id field
form_for(@post, :include_id => false) do |f|
f.text_field :title
f.fields_for(:comments) do |cf|
cf.text_field :title
# Emit ids again
cf.fields_for(:author, :include_id => true) do |af|
af.text_field :name
end
end
end
UPDATE: include_id_reworked.patch
Comments and changes to this ticket
-
wildchild May 9th, 2010 @ 06:14 PM
Patch included. Can anyone suggest a better option name? Also fixes #4550
# Disable hidden id field form_for(@post, :skip_model_key => true) do |f| f.text_field :title f.fields_for(:comments) do |cf| cf.text_field :title # Emit ids again cf.fields_for(:author, :skip_model_key => false) do |af| af.text_field :name end end end
-
Dan Pickett May 9th, 2010 @ 06:16 PM
- Tag changed from formbuilder, rails3 to bugmash, formbuilder, rails3
-
Daniel Cadenas May 16th, 2010 @ 01:19 AM
I've attached a patch
We changed the option name to include_id and to invert it's boolean value, made it work with the latest 2-3-stable, added some more tests and added some documentation.
-
wildchild June 2nd, 2010 @ 12:31 AM
Another idea is to check that object respond_to?(:to_key) and don't emit hidden id if result is negative? Thoughts?
-
wildchild June 17th, 2010 @ 04:38 AM
@Daniel your patch does not applies to master.
New alternative patch "Don't emit hidden id unless model respond_to?(:to_key)"
-
wildchild June 20th, 2010 @ 06:47 AM
- Assigned user set to José Valim
-
José Valim June 20th, 2010 @ 11:04 AM
to_key is a required method to be compliant with ActiveModel API. So if your model does not define to_key, something is really wrong. :include_key => false or :include_id => false seems to be a good way to go.
Daniel provided a good patch with documentation, it would be nice if the following patch have these as well.
-
José Valim September 1st, 2010 @ 08:41 AM
- State changed from new to stale
Marking as stale. If anyone has an interest in reopening this, please provide a patch.
-
gix November 5th, 2010 @ 09:59 PM
Adds an :emit_hidden_id option to #form_for and #fields_for that indicates whether a hidden id field is automatically appended.
-
wildchild November 9th, 2010 @ 10:48 AM
My previous patch with option name changed to :include_key. Docs included.
-
Ryan Bigg November 10th, 2010 @ 04:55 AM
- State changed from stale to open
Ticket now has patches.
-
wildchild November 12th, 2010 @ 04:24 AM
Would there be any chance to get it applied before 3.0.2 release?
-
gix February 25th, 2011 @ 06:20 AM
Any news on this? Suggestions/Feedback on the patches/approaches? Reasons to not merge one of them?
Without such a change it's impossible to correctly use non-AR-esque models (for example proper join models with composite keys) without using hacks and getting warnings left and right.
And please do not invalidate the ticket again just because one of the small patches does not apply cleanly anymore months after it has been posted.
-
wildchild February 25th, 2011 @ 06:32 AM
@gitx It cannot be applied on master due to some changes in form_helper. I am going to work on new patch this weekend. I think and hope that we should finish this ticket before 3.1.
-
wildchild February 25th, 2011 @ 10:14 AM
- Tag changed from bugmash, formbuilder, rails3 to bugmash, formbuilder, patch, rails3
Done. First patch with an option named :include_key and the second with option named :include_id. Docs and tests included. Please apply, test your apps and leave a response.
-
wildchild February 25th, 2011 @ 03:21 PM
Fixed documentation and code cleaned up according to IRC discussion.
-
Lenary February 28th, 2011 @ 10:28 PM
that last patch didn't apply to 3-0-stable or master for me. Could you refactor it all into a single patch please, wildchild
-
wildchild March 1st, 2011 @ 03:58 AM
@Lenary, you must use just include_id_reworked.patch and it applies smoothly on master.
-
wildchild March 4th, 2011 @ 02:46 PM
Anyone interested in this ticket probably can found #6487 useful too.
-
Santiago Pastorino March 4th, 2011 @ 02:50 PM
- Milestone set to 3.x
-
Repository March 4th, 2011 @ 06:43 PM
- State changed from open to committed
(from [0db915efd1240f493c50b7b9f5d1ea5f1e3eec10]) Add an option to FormBuilder to omit hidden field with id
[#4551 state:committed]
Signed-off-by: Santiago Pastorino santiago@wyeworks.com
https://github.com/rails/rails/commit/0db915efd1240f493c50b7b9f5d1e...
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>
People watching this ticket
Attachments
Tags
Referenced by
- 4551 Add an option to omit the creation of hidden field with object id when using fields_for [#4551 state:committed]