Hi Tim,

On Sat, 2009-07-04 at 00:53 +0200, Tim Mcd wrote:
> Is it possible to generate a model that way? Instead of,
> Test stat1:string stat2:integer stat3:string,
> is there a way to store arrays/hashes?
> 

I'm really not sure what you're asking, but I'll try and I'll explain a
little that might help you ask again, better, if you need to.

I assume your question is about script/generate model ....

That's generating a bunch of things for you, including a migration that,
when run, is going to create a table in a relational database with
fields named and typed the way you specified.  The model created is
initially just a two line text file that Rails uses to know which table
to 'talk to.'

So are you asking about storing arrays/hashes in a single field in a
relational database?  If so, see the 'serialize' method.  You'd type the
field as a blob.

> Would I just use 'integer[]' or etc? What if I wanted an array of
> different types? *sob*

In Ruby, which Rails is just helping you write, arrays can contain
elements of different types.  

irb(main):001:0> arraytest = Array.new
=> []
irb(main):002:0> arraytest[0] = 1
=> 1
irb(main):003:0> arraytest[1] = 'bob'
=> "bob"
irb(main):004:0> hash_element = Hash.new
=> {}
irb(main):005:0> hash_element = {:color => 'green'}
=> {:color=>"green"}
irb(main):006:0> arraytest[2] = hash_element
=> {:color=>"green"}
irb(main):007:0> arraytest.inspect
=> "[1, \"bob\", {:color=>\"green\"}]"

HTH,
Bill


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to