Sessions in Layered Dispatching

Can you use sessions in layered dispatching? I used them in direct
dispatching without any problems, but switching to layered throws an
error (saying session doesn’t exist).

Sorry if this is a double post, Google G. isn’t posting my message
for some reason.

Here is the error:

undefined local variable or method `session’ for
#UserService:0x4818e78

Here is the UserService class:

class UserService < ActionWebService::Base
web_service_api UserApi

def login(username, password)
logged_in_user = User.login(username,password)
if logged_in_user
session[:user_id] = logged_in_user.id
return true
else
return false
end
end

def get_all_users
return User.find(:all)
end
end

You can pass the current controller to your service like this

class UserService < AWS::Base
def initialize(controller)
@controller = controller
end

def login
@controller.session[…]
end
end

class ServiceController < ApplicationController
web_service(:user) { UserService.new(controller) }
end

Kent.

On 12/1/06, Jason B. [email protected] wrote:

web_service_api UserApi

def get_all_users
return User.find(:all)
end
end


Kent

Thanks!
I did this yesterday, and I tried to raise @controller.session[:user_id]
and it didn’t work. Stupid mistake on my part, raise
@controller.session[:user_id].to_s works much nicer :slight_smile:

Kent S. wrote:

You can pass the current controller to your service like this

class UserService < AWS::Base
def initialize(controller)
@controller = controller
end

def login
@controller.session[…]
end
end

class ServiceController < ApplicationController
web_service(:user) { UserService.new(controller) }
end

Kent.

On 12/1/06, Jason B. [email protected] wrote:

web_service_api UserApi

def get_all_users
return User.find(:all)
end
end


Kent

http://www.datanoise.com