[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Newbie questions

Tim

6/21/2006 2:24:00 AM

Probably a classic case of trying to run before I can crawl, but I'm
trying to build an app with some complexity to demo to Senior
Management to give them a taste of the power of Ruby. The current
spate of demo apps just don't have enough meat on the bones to use as
demos. I work for an investment management house and have years of
experience designing databases so I'm not entirely stupid but I'm
feeling the growing pains.

That being said, I have most of my MySQL database scoped out, have
imported millions of rows of production data into the database so it
looks real-world. I started by installing InstantRails on a WinXP
workstation. I've pulled a number of plugins (acts_as_versioned,
acts_as_dropdown) and the AjaxScaffold (to give everything a more
"professional" feel).

Here are my issues:

1) Whenever I start IRB and issue a require 'xxxxx' command, Ruby
responds with "Can't load file". The only way to get the require
command to work is to issue it with the full path name to the .rb file
as in: require 'C:\Rails\...............\mysql.rb' Is this right? Am I
missing something in my configuration (a path or series of paths) so
that I don't have to search for the file and issue the full path name?
2) I'm totally lost at this point when to use @variables versus
:variables or :symbols.
3) I have a model which has a belongs_to clause. Later on in the model
I have a method which says:
def inception
Model.parent.inception_date
end
If I open a Rails Console and say:
x = Model.find(12000)
puts x.inception
I get an error saying undefined method -- parent. BUT I can say in IRB
x = Model.parent.inception_date
Why is that?

4) Lastly (and I thank anyone brave enough to read all this), I'm
trying to figure out the best approach to performing complex
calculations between several tables. I have to join a series of tables
based on multiple values (which have all been indexed). Some of these
calculations (like cumulative returns) require retrieving data from
multiplel rows in each table at once and performing running totals and
calcs. I'm trying to figure out if it's possible to do this in a model
or if I'm better off trying to create intermediate temp tables and
basing a model on the temp tables.

So my first question would be: can you base a model on a temp table or
on a SQL Select? If so, how would you do it?
My other question is: if I have code outside of the def/end method
construction in a model when/how is it called/executed?

Thanks to anyone in advance for responding.

Tim
30 Answers

zycte

6/21/2006 10:30:00 AM

0

On 2006-06-21 04:23:40 +0200, Tim <tklemmer@lanline.com> said:
>
>
> Here are my issues:
>
> 1) Whenever I start IRB and issue a require 'xxxxx' command, Ruby
> responds with "Can't load file". The only way to get the require
> command to work is to issue it with the full path name to the .rb file
> as in: require 'C:\Rails\...............\mysql.rb' Is this right? Am I
> missing something in my configuration (a path or series of paths) so
> that I don't have to search for the file and issue the full path name?

In irb, ask the value of $LOAD_PATH. It contains the directories from
which you can load relatively.

> 2) I'm totally lost at this point when to use @variables versus
> :variables or :symbols.

@variable is an instance variable. If you assign to an @variable in any
method of a class, the variable stays in the class instance. :symbols
are symbols, that is, they are strings that are interned by Ruby, so
two symbols with the same name point to the same address and can be
compared very quickly. Rails uses a lot of :symbols, which can make it
a bit confusing at first. You should know that when you have to use a
:symbol, it is as a parameter of a method that will usually do some
metaprogramming. Look in the rails reference for the details of each
function.

> 3) I have a model which has a belongs_to clause. Later on in the model
> I have a method which says:
> def inception
> Model.parent.inception_date
> end
> If I open a Rails Console and say:
> x = Model.find(12000)
> puts x.inception
> I get an error saying undefined method -- parent. BUT I can say in IRB
> x = Model.parent.inception_date
> Why is that?

I don't understand why you call the parent method on the Model class
and not on the instance. You could do:

class Model
belongs_to :other

def inception
other.inception_date
end

end

class Other
# Rais adds an inception_date accessor here cause it is defined in
your database
end

senthil.nayagam@gmail.com

6/21/2006 11:20:00 AM

0

Hi Tim,

Have you tried "rails appliance"

a vmware based virtual appliance, which is preconfigured to get you
started

it has lighttpd, mysql,ssh, svn, ruby, gems, rails

you can run it in your windows xp or linux environment

you can download it from
http://www.vmware.com/vmtn/appliances/dir...

official homepage
http://senthilnayagam.com/home/show/rail...

rails appliance forum
http://www.railsappl...


it runs using vmware player which is freely available for windows and
linux
http://www.vmware.com/produc...


regards
A.Senthil Nayagam


Tim wrote:
> Probably a classic case of trying to run before I can crawl, but I'm
> trying to build an app with some complexity to demo to Senior
> Management to give them a taste of the power of Ruby. The current
> spate of demo apps just don't have enough meat on the bones to use as
> demos. I work for an investment management house and have years of
> experience designing databases so I'm not entirely stupid but I'm
> feeling the growing pains.
>
> That being said, I have most of my MySQL database scoped out, have
> imported millions of rows of production data into the database so it
> looks real-world. I started by installing InstantRails on a WinXP
> workstation. I've pulled a number of plugins (acts_as_versioned,
> acts_as_dropdown) and the AjaxScaffold (to give everything a more
> "professional" feel).
>
> Here are my issues:
>
> 1) Whenever I start IRB and issue a require 'xxxxx' command, Ruby
> responds with "Can't load file". The only way to get the require
> command to work is to issue it with the full path name to the .rb file
> as in: require 'C:\Rails\...............\mysql.rb' Is this right? Am I
> missing something in my configuration (a path or series of paths) so
> that I don't have to search for the file and issue the full path name?
> 2) I'm totally lost at this point when to use @variables versus
> :variables or :symbols.
> 3) I have a model which has a belongs_to clause. Later on in the model
> I have a method which says:
> def inception
> Model.parent.inception_date
> end
> If I open a Rails Console and say:
> x = Model.find(12000)
> puts x.inception
> I get an error saying undefined method -- parent. BUT I can say in IRB
> x = Model.parent.inception_date
> Why is that?
>
> 4) Lastly (and I thank anyone brave enough to read all this), I'm
> trying to figure out the best approach to performing complex
> calculations between several tables. I have to join a series of tables
> based on multiple values (which have all been indexed). Some of these
> calculations (like cumulative returns) require retrieving data from
> multiplel rows in each table at once and performing running totals and
> calcs. I'm trying to figure out if it's possible to do this in a model
> or if I'm better off trying to create intermediate temp tables and
> basing a model on the temp tables.
>
> So my first question would be: can you base a model on a temp table or
> on a SQL Select? If so, how would you do it?
> My other question is: if I have code outside of the def/end method
> construction in a model when/how is it called/executed?
>
> Thanks to anyone in advance for responding.
>
> Tim

Tim

6/23/2006 1:37:00 AM

0

THanks for the response. That helps clear a few things up. As fasr as
the Model.parent.date reference, that was my bad as I wasn't sure
where I had to start the traversing of the tables. It makes sense now
that I realize I'm in the class and at the top of this chain.

zycte <zycte@mailinator.com> wrote:

>On 2006-06-21 04:23:40 +0200, Tim <tklemmer@lanline.com> said:
>>
>>
>> Here are my issues:
>>
>> 1) Whenever I start IRB and issue a require 'xxxxx' command, Ruby
>> responds with "Can't load file". The only way to get the require
>> command to work is to issue it with the full path name to the .rb file
>> as in: require 'C:\Rails\...............\mysql.rb' Is this right? Am I
>> missing something in my configuration (a path or series of paths) so
>> that I don't have to search for the file and issue the full path name?
>
>In irb, ask the value of $LOAD_PATH. It contains the directories from
>which you can load relatively.
>
>> 2) I'm totally lost at this point when to use @variables versus
>> :variables or :symbols.
>
>@variable is an instance variable. If you assign to an @variable in any
>method of a class, the variable stays in the class instance. :symbols
>are symbols, that is, they are strings that are interned by Ruby, so
>two symbols with the same name point to the same address and can be
>compared very quickly. Rails uses a lot of :symbols, which can make it
>a bit confusing at first. You should know that when you have to use a
>:symbol, it is as a parameter of a method that will usually do some
>metaprogramming. Look in the rails reference for the details of each
>function.
>
>> 3) I have a model which has a belongs_to clause. Later on in the model
>> I have a method which says:
>> def inception
>> Model.parent.inception_date
>> end
>> If I open a Rails Console and say:
>> x = Model.find(12000)
>> puts x.inception
>> I get an error saying undefined method -- parent. BUT I can say in IRB
>> x = Model.parent.inception_date
>> Why is that?
>
>I don't understand why you call the parent method on the Model class
>and not on the instance. You could do:
>
>class Model
> belongs_to :other
>
> def inception
> other.inception_date
> end
>
>end
>
>class Other
> # Rais adds an inception_date accessor here cause it is defined in
>your database
>end

Tim

6/23/2006 1:40:00 AM

0

Thanks. I have not tried rails appliance. I'm a big fan of VMWare
products but not crazy about VM Player. It's tough to move from VM
Workstation where you have lots of power to VM Player where you have
none.

I had thought about isolating Rails in a workstation session but I
didn't want the overhead nor didn't want to isolate the rails app
within VMWare. It becomes too cumbersome to demo.


"Senthilnayagam" <senthil.nayagam@gmail.com> wrote:

>Hi Tim,
>
>Have you tried "rails appliance"
>
>a vmware based virtual appliance, which is preconfigured to get you
>started
>
>it has lighttpd, mysql,ssh, svn, ruby, gems, rails
>
>you can run it in your windows xp or linux environment
>
>you can download it from
>http://www.vmware.com/vmtn/appliances/dir...
>
>official homepage
>http://senthilnayagam.com/home/show/rail...
>
>rails appliance forum
>http://www.railsappl...
>
>
> it runs using vmware player which is freely available for windows and
>linux
>http://www.vmware.com/produc...
>
>
>regards
>A.Senthil Nayagam
>
>
>Tim wrote:
>> Probably a classic case of trying to run before I can crawl, but I'm
>> trying to build an app with some complexity to demo to Senior
>> Management to give them a taste of the power of Ruby. The current
>> spate of demo apps just don't have enough meat on the bones to use as
>> demos. I work for an investment management house and have years of
>> experience designing databases so I'm not entirely stupid but I'm
>> feeling the growing pains.
>>
>> That being said, I have most of my MySQL database scoped out, have
>> imported millions of rows of production data into the database so it
>> looks real-world. I started by installing InstantRails on a WinXP
>> workstation. I've pulled a number of plugins (acts_as_versioned,
>> acts_as_dropdown) and the AjaxScaffold (to give everything a more
>> "professional" feel).
>>
>> Here are my issues:
>>
>> 1) Whenever I start IRB and issue a require 'xxxxx' command, Ruby
>> responds with "Can't load file". The only way to get the require
>> command to work is to issue it with the full path name to the .rb file
>> as in: require 'C:\Rails\...............\mysql.rb' Is this right? Am I
>> missing something in my configuration (a path or series of paths) so
>> that I don't have to search for the file and issue the full path name?
>> 2) I'm totally lost at this point when to use @variables versus
>> :variables or :symbols.
>> 3) I have a model which has a belongs_to clause. Later on in the model
>> I have a method which says:
>> def inception
>> Model.parent.inception_date
>> end
>> If I open a Rails Console and say:
>> x = Model.find(12000)
>> puts x.inception
>> I get an error saying undefined method -- parent. BUT I can say in IRB
>> x = Model.parent.inception_date
>> Why is that?
>>
>> 4) Lastly (and I thank anyone brave enough to read all this), I'm
>> trying to figure out the best approach to performing complex
>> calculations between several tables. I have to join a series of tables
>> based on multiple values (which have all been indexed). Some of these
>> calculations (like cumulative returns) require retrieving data from
>> multiplel rows in each table at once and performing running totals and
>> calcs. I'm trying to figure out if it's possible to do this in a model
>> or if I'm better off trying to create intermediate temp tables and
>> basing a model on the temp tables.
>>
>> So my first question would be: can you base a model on a temp table or
>> on a SQL Select? If so, how would you do it?
>> My other question is: if I have code outside of the def/end method
>> construction in a model when/how is it called/executed?
>>
>> Thanks to anyone in advance for responding.
>>
>> Tim

senthil.nayagam@gmail.com

6/23/2006 4:55:00 AM

0

most new rails users face some trouble with development or staging
environment, they dont get required stuff working. That was one
motivation for me to develop rails appliance.


yes it needs some more resources, 4 gb free space and atleast 512mb ram
to run rails appliance. but then you are running it on the real thing
what real rails guys use, lighty and FCGI , with all stuff
pre-configured, has SVN to store your repos. and this can run on your
corporate lan, without any licensing headaches.

I am using it on my laptop for those presentations which matter. my
laptop is a compaq turion64 1.8ghz, with 512 MB ram.

regards
A.Senthil Nayagam
http://senthiln...

Tim wrote:
> Thanks. I have not tried rails appliance. I'm a big fan of VMWare
> products but not crazy about VM Player. It's tough to move from VM
> Workstation where you have lots of power to VM Player where you have
> none.
>
> I had thought about isolating Rails in a workstation session but I
> didn't want the overhead nor didn't want to isolate the rails app
> within VMWare. It becomes too cumbersome to demo.
>
>

Chriss

11/16/2010 12:26:00 AM

0

D.A.Tsenuf a ?crit :
> Les Chinois ont toujours agi comme si la Chine etait le nombril de la
> planete.'

tiens comme les ricains !!!

;-)

--
L'homme n'est pas fait pour travailler. La preuve, c'est que ca le
fatigue.
Georges Courteline


Chriss

11/16/2010 12:27:00 AM

0

D.A.Tsenuf a ?crit :
> L'Islam a TOUJOURS etee une religion AGGRESSIVEMENT totalitaire.
> Et l'Islam a TOUJOURS "pr?ch?e la guerre permanente"

tiens comme les ricains.... Irak, Afghanistan.... cela ne te dit rien
??

:P :P

--
Une auto-stoppeuse est une jeune femme g?n?ralement jolie et court
v?tue qui se trouve sur votre route quand vous ?tes avec votre femme.
Woody Allen


Lynda Labelle

11/16/2010 1:21:00 AM

0

Le 15/11/10 15:42, D.A.Tsenuf a ?crit :

> Des problemes avec l'article

Ouais, il est plein de mots que tu comprends pas.

> 1) L'Islam a TOUJOURS etee une religion AGGRESSIVEMENT totalitaire.

Rappelle-moi les attentats islamistes des ann?es 1940, 50, 60, 70...
Et celles du 19e si?cle?

> Et l'Islam a TOUJOURS "pr?ch?e la guerre permanente"

Rappelle-mi les guerres islamistes du si?cle pass?.

> Dar-al-Harb, ca vous dit rien ?

Non. C'est quoi?

> 2) La Chine a TOUJOURS etee "ultra-nationaliste"

Toujours, toujours... Avant 1945 aussi?

> Les Chinois ont toujours agi comme si la Chine etait le nombril de la
> planete.'

Comme les USA.

S'pion

11/16/2010 1:30:00 AM

0

Le 2010-11-15 20:20, Lynda Labelle a ?crit :
> Le 15/11/10 15:42, D.A.Tsenuf a ?crit :
>
>> Des problemes avec l'article
>
> Ouais, il est plein de mots que tu comprends pas.
>
>> 1) L'Islam a TOUJOURS etee une religion AGGRESSIVEMENT totalitaire.
>
> Rappelle-moi les attentats islamistes des ann?es 1940, 50, 60, 70...
> Et celles du 19e si?cle?
>
>> Et l'Islam a TOUJOURS "pr?ch?e la guerre permanente"
>
> Rappelle-mi les guerres islamistes du si?cle pass?.
>
>> Dar-al-Harb, ca vous dit rien ?
>
> Non. C'est quoi?
>
>> 2) La Chine a TOUJOURS etee "ultra-nationaliste"
>
> Toujours, toujours... Avant 1945 aussi?
>
>> Les Chinois ont toujours agi comme si la Chine etait le nombril de la
>> planete.'
>
> Comme les USA.


Salut ma belle.


Anne G

11/16/2010 1:51:00 AM

0

Le 15/11/10 18:30, Gino Lebeau a ?crit :
> Le 2010-11-15 20:20, Lynda Labelle a ?crit :

> Salut ma belle.

:-DDD

--
(trop poche pour me faire une identit? de Moris Leboeuf pour r?pondre
?meuh?.)