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?
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.