I need some advice. I have a form that has data from 4 different tables
and about 10 values to save and keep until the form is finally sent.
Where would you save the 10 values (all strings or integers, of course)?
Session? Cookie? Pass them around as parameter?
I'm a bit confused and would highly appreciate any suggestions.
Thanks!
--
Posted via http://www.ruby-forum.com/.
If it's only one request cycle, there's no real need to save temp data.
What are you trying to do?
>
> I'm a bit confused and would highly appreciate any suggestions.
>
> Thanks!
Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
> That's exactly my problem, otherwise I would be using variables. It's
> many request cycles going back and forth that's why I need a proper way
> to save some data. I'm doing it by passing parameters but it's confusing
> and I don't like parameter when handling so many variables.
Is there any chance your form data needs to persist across sessions,
(as in user leaves, comes back, resumes filling in unfinished form)?
If not, you could save your variables in a hash in session. Otherwise
I would create a Form model and save it to the DB.
FWIW,
--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
twitter: @hassan
> No, user doesn't leave. It just could end up in many request cycles.
> Didn't have the Session a very small amount of data it can save?
That depends on how you're handling sessions, but the more I think
about it, I'd just go with the Form object and saving changes to the
DB across requests.
If you are only talking about a few hundred bytes or less then you can
certainly save it in the session. The alternative is to use fields in
something like the User table, assuming there is one.
Colin
So I guess I should go for the session?
What do you mean by "current number of users"? Do you mean how many
users are logged on? I got the impression in your original post that
we were talking about data entered by the user. How do you know how
many users are currently logged on? Remember that a session is on a
user by user basis. If you want to remember data across users I think
you will have to put it in the db.
Colin
Best regards
Peter De Berdt
Is it more clear now?
Yes, in that case I would use the session, if you are really sure you
can't just update the db as you go along. What is the issue with just
updating the db as you go? The user will get really hacked off if he
spends half an hour entering multiple forms only to lose it all when
he loses connection for some reason.
Colin
Well, good point but I'm not sure if I unerstood what you exactly mean
by update db as you go. The group and it's users (which are being added
in the sub form) have a m:n-relation so you'd create that relaion for
each and every user being added and delete it again if something goes
wrong or the user hits the cancel button? Looks like a lot of
unnecessary db traffic to me. Or would you create another table only for
the temp data?
I do not know enough about the application to say much more. I was
suggesting updating the actual data rather than a temp table, but it
was only a suggestion. I generally would suggest to do things the
easiest way initially and only complicate it it if becomes necessary,
though which is the easy way in your case I do not know. Certainly
don't worry about the db traffic unless it becomes an issue.
Whichever route you go down make sure you have tests in place so you
can refactor later and know it still works.
Colin
Alright, thanks a lot to all of you! I'll keep both solutions in mind
and see what's easier to use.