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
-
wildchild
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
- Tag changed from formbuilder, rails3 to bugmash, formbuilder, rails3
-
Daniel Cadenas
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
Another idea is to check that object respond_to?(:to_key) and don't emit hidden id if result is negative? Thoughts?
-
wildchild
@Daniel your patch does not applies to master.
New alternative patch "Don't emit hidden id unless model respond_to?(:to_key)"
-
wildchild
- Assigned user set to José Valim
-
José Valim
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
- State changed from new to stale
Marking as stale. If anyone has an interest in reopening this, please provide a patch.
-
gix
Adds an :emit_hidden_id option to #form_for and #fields_for that indicates whether a hidden id field is automatically appended.
-
wildchild
My previous patch with option name changed to :include_key. Docs included.
-
wildchild
Would there be any chance to get it applied before 3.0.2 release?
-
gix
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
@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
- 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
Fixed documentation and code cleaned up according to IRC discussion.
-
Lenary
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
@Lenary, you must use just include_id_reworked.patch and it applies smoothly on master.
-
Santiago Pastorino
- Milestone set to 3.x
-
Repository
- 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...
