-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested forms #99
Comments
From @dariocravero on September 9, 2014 16:32 @fgarcia I know it might be a bit confusing and that probably the whole form builders section needs to be redone. I'll get started using your example here :). First of all, the form builder helpers expect the symbol you use to be either an instance variable available to the view or an object it can instantiate on the fly. Having said that, you can still force the name of the field by using the Here's a sample app that should work with it:
It should render:
Notice how I've merged the usage of Now, let's jump into nested models/data structures. The issue you're facing there is that you're trying to use an association that doesn't exist or isn't explicitly declared. The helper is only trying to access
That would render something like:
That would be the case of a one to one association in a relational db. If you were to return an array of elements, it would then render as many as you return. So, say we modify `models/model.rb to look like this:
It should output:
If we were to add an ORM like, say Sequel, and name the models
And that's kind of how the whole relations thing would go when you layered up to using ORM models together with the form builder. Hope this helped clarify things a bit and if not, let me know and we'll look at it in more depth. Here's the demo app. :) |
From @dariocravero on September 9, 2014 16:32 @padrino/core-members should we update the guides with something along the lines of this? |
From @fgarcia on September 9, 2014 17:0 That was more exhaustive than I expected! Thanks a lot I downloaded your example, played with it and verified one thing... when you mentioned Your example uses form_for which I thought could achieve the result I wanted using a real model. Now it is so much clear! However in my example I used form_tag because I wanted to use the helpers without an existing model. My assumption was that the helpers behaved like in Rails. I've just tested this quickly in Rails:
The last line is rendered as:
That was my expectation when combining fields_for with form_tag It is my fault misunderstanding since I assumed that if fields_for could be used within form_tag an no prefixed model, then I expected that no model at all was required :-( thanks for the lesson! |
From @dariocravero on September 9, 2014 17:31 I get your pain point and I agree that it should probably work without an explicit model too, e.g., what if you need to create a form for a service you don't manage in the same app but you know the structure of? Perhaps we could try to mimic that behaviour @padrino/core-members thoughts? |
From @halfdan on November 6, 2015 11:54 It'd also be great if it would allow to render an "Add" button that adds additional nested elements on the fly (in the DOM, using javascript). |
From @fgarcia on September 9, 2014 14:37
I am not having the behavior I expected from the
fields_for
form helper. This is what I am trying to do (Slim template):The text field above is generated as:
I expected the field to be inside 'model', not inside 'object':
Also I cannot nest again inside like this:
With that I get the error
undefined method 'inside'
and my expected output was:Maybe I am doing something wrong expecting something similar to the rails helpers, so any advice using these helpers to get nested forms (without object) would be welcome.
Copied from original issue: padrino/padrino-framework#1760
The text was updated successfully, but these errors were encountered: