On Jul 13, 2007, at 10:04 PM, Craig Johnson wrote:

> John, appreciate your shot at it...
>
> But---(and I don't' want to be a "Joe" here...) if anyone
> has build a site/ruby app which creates and manipulates
> complex object classes (things that have Arrays, or Hashes within
> their Class definitions)...
> How did you store those things in the database...
>
> for example ... if I have a recipe which has Steps
> which have ingredients tied to those steps I might want to
> create an array of Steps, each of which can have both Actions and
> an array of ingredients...
> But...once a user has put in the receipe...and I've populated all  
> those
> objects within the instance....
> I want to save it...
> How?
>
> throw me some ideas...
> I'm thinking that I have to serialize the class...and that is  
> what's needed.
>
> cj:)
>
> -----Original Message-----
> From: John Joyce [mailto:dangerwillrobinsondanger / gmail.com]
> Sent: Friday, July 13, 2007 8:45 PM
> To: ruby-talk ML
> Subject: Re: Web Databases and Objects
>
>
> On Jul 13, 2007, at 9:22 PM, Craig Johnson wrote:
>
>> OK..I'm having a mental block.
>> I have a website started with Ruby on Rails.
>> I've got this object Hierarchy in mind.
>>  the simple "it's a database" stuff is fine.but when it comes to
>> the Arrays
>> of Hashes that make
>>   up some of the objects within the custom class.the relationship
>> to the
>> database and what happens when
>>   I close down the environment (and in future want to start up site.)
>> So how do I Save and retrieve that stuff? do I have to do the
>> Object/Relational mapping myself or
>>
>>   do I depend on the "serialize" function/method for the class?
>> the examples I've seen don't have a user create and populate a  
>> complex
>> object and then
>>
>> save and retrieve it...things that are saved and retrieved seem  
>> pretty
>> simple---though there
>>
>> are lots of instantiations and work live---but I need to create a
>> datastore
>> that gets extended and
>>
>> hit with queries---Am I going to have to recreate and repopulate via
>> "deserialize" ?
>> I imagine the answer is obvious---but it eludes my feeble mind..
>>
>> Help?
>> cj:-)
>>
>
After creating your database schema, usually using script/generate  
migration migration_name,

If you run the old
ruby script/generate scaffold
You'll be faced with a simple CRUD application.
It includes the pretty standard Rails naming of methods in the  
controllers, it's in all of the tutorials online and elsewhere.
It is a bit cryptic as there isn't an explicit 'save by clicking  
here' or anything,
but basically, the controllers talk to active record and do SQL for you.
SQL doesn't really do a 'save' as such, it saves as soon as the  
record is created, the two are one and the same.
If you follow the conventions of Rails (I'm still learning them  
myself, there is a lot to keep in your head)
naming conventions and what not, things should be saved and available  
the next time.
The only thing to really shut down is the database and the server.
If the controllers, models, views and database are set up correctly,  
your data should be saved.

I'm going to recommend the Sitepoint book Build Your Own Ruby On  
Rails Applications, I just bought it today... based on a  
recommendation or two that gave it high marks for going into details  
like this. I'm also trying to get details like this, but different.  
I'll be reading it tomorrow and if I find something clearer, I'll let  
you know.

You could also try the Rails list but I've found it's not too  
beginner friendly sometimes. It's pretty geared (like many of the  
books) toward people that have built web apps in other languages before.