# Form issues : partials + AJAX vs simple JS / separate views + form\_fors vs one view and fields\_fors

**URL:** <https://www.ruby-forum.com/t/form-issues-partials-ajax-vs-simple-js-separate-views-form-fors-vs-one-view-and-fields-fors/156161>\
**Category:** Rails\
**Created:** [December 22, 2008, 12:39am UTC](https://www.ruby-forum.com/t/form-issues-partials-ajax-vs-simple-js-separate-views-form-fors-vs-one-view-and-fields-fors/156161 "2008-12-22T00:39:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![iKs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c77e96/32.png) [@iKs](https://www.ruby-forum.com/u/iKs)\
**Post date:** [December 22, 2008, 12:39am UTC](https://www.ruby-forum.com/t/form-issues-partials-ajax-vs-simple-js-separate-views-form-fors-vs-one-view-and-fields-fors/156161/1 "2008-12-22T00:39:19Z")

</div>

Hi all!

I am coding an application that keeps track of request to create  
college courses. An identified user (logically a faculty member)  
completes a form indicating the name of the course, the professor in  
charge, the course’s code, the date and place, the possible  
coprofessors and TAs and the type of website he or she wants to use as  
a teaching help (WebCT, Sakai, etc.).

I have two problems about what I’m doing.

First of all, we can have from 0 to inf coprofessors and TAs.  
Therefore I need to be able to add fields to my form dynamically. I  
know it is possible through pure Javascript with DOM but most websites  
and books about Rails tend to tell me to use AJAX and partials. I feel  
it’s plain stupid to recontact the server just to add a blank \<input /

> . What is the best way? I also need it to work when Javascript is  
> disabled. Should I use a plain HTML version only that uses one form to  
> add TAs or coprofessors one at a time?

Second I’m not sure if my usage of form\_for and fields\_for is the  
wisest one. For now, I have one big form (still OK to use I feel) with  
infos about TAs, coprofessors, periods, places, etc. all in one place.  
In the back-end of course they are different models so I use a  
form\_for Course and several fields\_for (in partials). Should I instead  
separate it in several pages/views with form\_fors in each of them?  
What the “Railser” way to do it?

Thank you for your help and time!

-Max

---

<div class="post-metadata">

**Author:** ![iKs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c77e96/32.png) [@iKs](https://www.ruby-forum.com/u/iKs)\
**Post date:** [December 22, 2008, 4:53am UTC](https://www.ruby-forum.com/t/form-issues-partials-ajax-vs-simple-js-separate-views-form-fors-vs-one-view-and-fields-fors/156161/2 "2008-12-22T04:53:57Z")

</div>

On Dec 21, 3:36 pm, iKs [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
[…]

> First of all, we can have from 0 to inf coprofessors and TAs.  
> Therefore I need to be able to add fields to my form dynamically. I  
> know it is possible through pure Javascript with DOM but most websites  
> and books about Rails tend to tell me to use AJAX and partials. I feel  
> it’s plain stupid to recontact the server just to add a blank .

I would agree with you. The only advantage of recontacting the server  
is that you can have it spit out a new copy of a partial – and  
reinterpret the ERb each time. But judicious use of cloneNode in JS  
should work just as well.

> What is the best way? I also need it to work when Javascript is  
> disabled. Should I use a plain HTML version only that uses one form to  
> add TAs or coprofessors one at a time?

That’s a usability decision best left to you and your users.

> Second I’m not sure if my usage of form\_for and fields\_for is the  
> wisest one. For now, I have one big form (still OK to use I feel) with  
> infos about TAs, coprofessors, periods, places, etc. all in one place.  
> In the back-end of course they are different models so I use a  
> form\_for Course and several fields\_for (in partials). Should I instead  
> separate it in several pages/views with form\_fors in each of them?  
> What the “Railser” way to do it?

Again, use whatever UI will be best for your users. It’s perfectly OK  
to use lots of fields\_for to get different models onto one form if  
that’s what the UI calls for.

> Thank you for your help and time!
> 
> -Max

## Best,

Marnen Laibow-Koser  
removed\_email\_address@domain.invalid  
[http://www.marnen.org](http://www.marnen.org)
