Ruby on Rails
Monday, February 17, 2020
accepts_nested_attributes_for explicitly checks for associations to exist https://github.com/rails/rails/blob/f33d52c95217212cbacc8d5e44b5a8e3cdc6f5b3/activerecord/lib/active_record/nested_attributes.rb#L340
fields_for does not require accepts_nested_attributes_for to be defined, but it won't behave the same without that, you can inspect the generated html on both cases
El lun., 17 feb. 2020 a las 6:19, Nicholas Schwaderer (<nicholas.schwaderer@gmail.com>) escribió:
Hello again Fugee,Fields in forms in Rails do not necessarily have to correspond with model attributes.Generally, you might find the Rails edge guide on forms very helpful- as well as the `form_with` API docs which are a bit more specific for some of these questions.Nick Schwaderer--On Mon, 17 Feb 2020 at 07:45, fugee ohu <fugee279@gmail.com> wrote:--
On Monday, February 17, 2020 at 12:38:03 AM UTC-5, Walter Lee Davis wrote:You may use fields_for for any object that you have declared "accepts_nested_attributes_for" in your form's parent model. It obviously makes the most sense to do this with a related object.
Walter
> On Feb 16, 2020, at 10:41 PM, fugee ohu <fuge...@gmail.com> wrote:
>
> Can I use fields_for for any models or do they have to be associated?
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/09881329-3137-4c90-94a1-6495bccc90bd%40googlegroups.com.In my app users have many artists, artists have many tourdates, artists have many venues, users have many venues through artists, tour_dates when added have to provide a venue so they can select from clubs or festivals that are included in the app, and they can also create a user defined venue, or select from previous user defined venues I had this working before I started concerning myself with associations by prepending all the venue fields with venue so state and city become venue_state and venue_city and I add an attribute_accessor to the tour_dates model for each venue field I feel like that still the way to do it, as long as the user defined venues belong to the artist and user so if the user ever deletes the artist the venue will be deleted also
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f2ba1d66-8420-41e9-b228-2456080f0ffb%40googlegroups.com.
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAGN3KYykHS73kLZ1G4XuQqJrRwzjrJ1wPa2vmtT%2Bib8z-ffMyg%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAPS3bcCtF2x6DD6TGsixdK3sU6uW67v0mNFEZen85CZeMeO9DA%40mail.gmail.com.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment