HighDots Forums  

generate model Test stats:hash/array? Is it possible?

Ruby On Rails Talk Ruby On Rails programming language mailing list


Discuss generate model Test stats:hash/array? Is it possible? in the Ruby On Rails Talk forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Tim Mcd
 
Posts: n/a

Default generate model Test stats:hash/array? Is it possible? - 07-03-2009 , 06:53 PM






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?

Would I just use 'integer[]' or etc? What if I wanted an array of
different types? *sob*
--
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
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 rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
  #2  
Old   
bill walton
 
Posts: n/a

Default Re: generate model Test stats:hash/array? Is it possible? - 07-03-2009 , 07:36 PM






Hi Tim,

On Sat, 2009-07-04 at 00:53 +0200, Tim Mcd wrote:
Quote:
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.

Quote:
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 rubyonrails-talk (AT) googlegroups (DOT) com
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe (AT) googlegroups (DOT) com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.