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 Groups isn''t posting my message for some reason. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Best <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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 >-- Kent --- http://www.datanoise.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 :) Kent Sibilev 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 Best <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> web_service_api UserApi >> >> def get_all_users >> return User.find(:all) >> end >> end >> > > -- > Kent > --- > http://www.datanoise.com-- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---