[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Correct way to use DRb within a Rails Controller?

x1

12/14/2005 4:00:00 AM

[not really rails specific]
I'm unsure about what should be placed where or if it even matters.
Here's the basic rails controller:

-------please_work_controller.rb----------
class PleaseWork < ApplicationController
def get_name
@name = retrieve.name
end
def get_age
@age = retrieve.age
end
end
-------/please_work_controller.rb--------
To create your typical client DRb connection, you'll need the following:

require 'drb'
DRb.start_service
retrieve = DRbObject.new(nil,"druby://#{hostname}:#{port}")

Where should these definitions be placed? They seem to work just about
anywhere but whats the optimal placement? Also, I realize retrieve
does not *need* to be defined but since it is used throughout the
class in other methods as such..

Thanks as usual!


1 Answer

Eric Hodel

12/15/2005 2:31:00 AM

0

On Dec 13, 2005, at 7:59 PM, x1 wrote:

> [not really rails specific]
> I'm unsure about what should be placed where or if it even matters.
> Here's the basic rails controller:
>
> -------please_work_controller.rb----------
> class PleaseWork < ApplicationController
> def get_name
> @name = retrieve.name
> end
> def get_age
> @age = retrieve.age
> end
> end
> -------/please_work_controller.rb--------
> To create your typical client DRb connection, you'll need the
> following:
>
> require 'drb'
> DRb.start_service
> retrieve = DRbObject.new(nil,"druby://#{hostname}:#{port}")

Depending upon how long your DRb server lives you can probably make
retrieve a global and put it in environment.rb. Score bonus points
for using NamedIdConv.

> Where should these definitions be placed? They seem to work just about
> anywhere but whats the optimal placement? Also, I realize retrieve
> does not *need* to be defined but since it is used throughout the
> class in other methods as such..
>
> Thanks as usual!

--
Eric Hodel - drbrain@segment7.net - http://se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...