do i need associations to use fields_for

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

do i need associations to use fields_for

fugee ohu
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/09881329-3137-4c90-94a1-6495bccc90bd%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: do i need associations to use fields_for

Walter Lee Davis
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 <[hidden email]> 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 [hidden email].
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/09881329-3137-4c90-94a1-6495bccc90bd%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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/759C296E-0C97-47A2-9C0E-0088DFBFFB17%40wdstudio.com.
Reply | Threaded
Open this post in threaded view
|

Re: do i need associations to use fields_for

fugee ohu


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 <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="C-RQm8npBAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">fuge...@...> 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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="C-RQm8npBAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonra...@googlegroups.com.
> To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-talk/09881329-3137-4c90-94a1-6495bccc90bd%40googlegroups.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/09881329-3137-4c90-94a1-6495bccc90bd%40googlegroups.com&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/09881329-3137-4c90-94a1-6495bccc90bd%40googlegroups.com&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-talk/09881329-3137-4c90-94a1-6495bccc90bd%40googlegroups.com.


If you use accepts_nested_attributes_for in a model without an association rails will raise an error In my models users have many artists, artists have many tour_dates and tour_dates have many user_venues I need to add fields for user_venues to the tour_dates form Pretty confused what to do

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f0c2006c-4cdc-4994-8e15-53fa34cb7a39%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: do i need associations to use fields_for

fugee ohu
In reply to this post by Walter Lee Davis


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 <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="C-RQm8npBAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">fuge...@...> 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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="C-RQm8npBAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonra...@googlegroups.com.
> To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-talk/09881329-3137-4c90-94a1-6495bccc90bd%40googlegroups.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/09881329-3137-4c90-94a1-6495bccc90bd%40googlegroups.com&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/09881329-3137-4c90-94a1-6495bccc90bd%40googlegroups.com&#39;;return true;">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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f2ba1d66-8420-41e9-b228-2456080f0ffb%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: do i need associations to use fields_for

Nicholas Schwaderer
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 <[hidden email]> 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 <[hidden email]> 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 [hidden email].
> 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 [hidden email].
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAGN3KYykHS73kLZ1G4XuQqJrRwzjrJ1wPa2vmtT%2Bib8z-ffMyg%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: do i need associations to use fields_for

Ariel Juodziukynas

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 (<[hidden email]>) 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 <[hidden email]> 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 <[hidden email]> 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 [hidden email].
> 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 [hidden email].
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 [hidden email].
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAPS3bcCtF2x6DD6TGsixdK3sU6uW67v0mNFEZen85CZeMeO9DA%40mail.gmail.com.