Newbie questions

T

Tim

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
 
Z

zycte

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 :eek:ther

def inception
other.inception_date
end

end

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

Senthilnayagam

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/directory/220

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

rails appliance forum
http://www.railsappliance.org/


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


regards
A.Senthil Nayagam
 
T

Tim

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.
 
T

Tim

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.
 
S

Senthilnayagam

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://senthilnayagam.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top