speaking
2011-Jan-03 03:55 UTC
I can not read cookie values when I try to access a method from a RoR Application to another RoR Application
I will try to explain as best I can my problem, because it is a lot of time that I am trying to solve it without success. I hope someone can really help me, however banal it may seem. So... I have two RoR 3 applications: - APP1: www.app1.example.com - APP2: www.app2.example.com Notice (if it helps): I do not use www.example.com as a developed RoR application, for now. At the moment it is only a "nil" project, that is a RoR basic application simply generated through the command ''rails new example'' in the Terminal. In APP1 I have a ''APP1/controllers/user_authentications_controller.rb'' with the following code to set user''s cookies: def create ... cookies.signed[:current_user_id] = { :value => [user.id, user.make_user_id_salt(user.id)], :expires => 15.days.from_now, :domain => ".example.com" } ... end that means (I know) I set cookies accessible from all ''www.subdomain.example.com''. In fact, normally, I can access the value of the cookie with the code ''cookies[:current_user_id]'' both from APP1 and APP2. The problem happens when I try to access the value of the cookie by making a request from APP1 to APP2 and vice versa. For example, using in APP2 the code Net::HTTP.get( URI.parse( www.app1.example.com/users ) ) and having in ''''APP1/controllers/users_controller.rb'''' the code def index @check_var = cookies[:current_user_id] end the debug of the @check_var in the ''''APP1/views/users/index.html.rb'''' shows me a blank value. For this reason I can not even use the conditional constructs and similar! This is only an example, but it happens also when I use the REST approach with API, and I think also in other cases when I make an external request to APPs. It seems that RoR does not follow cookies. So the question is: is it possible to get/share cookie or session information between more RoR applications? I use a Mac with OS "Snow Leopard" v10.6.5, Apache2 and Phusion Passenger. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Jan-03 12:44 UTC
Re: I can not read cookie values when I try to access a method from a RoR Application to another RoR Application
> > > > that means (I know) I set cookies accessible from all > ''www.subdomain.example.com''. In fact, normally, I can access the value > of the cookie with the code ''cookies[:current_user_id]'' both from APP1 > and APP2. >Always worth double checking in the browser that the cookie got set as you intended> The problem happens when I try to access the value of the cookie by > making a request from APP1 to APP2 and vice versa. For example, using > in APP2 the code > > Net::HTTP.get( URI.parse( www.app1.example.com/users ) ) >I think you have a misconception of how cookies work. When you set a cookie your http response will have a Set-Cookie. The browsers reads this and then knows that on subsequent requests to appropriate pages it should send that info. It doesn''t magically affect http requests made by your app. If you want a request you make via http to send a cookie then you need to craft an appropriate Cookie: header for that request. Similarly, if a cookie is created in response to a request you make using net/http, it will never make it to the user, unless you forward on the set-cookie header. Fred> and having in ''''APP1/controllers/users_controller.rb'''' the code > > def index > @check_var = cookies[:current_user_id] > end > > the debug of the @check_var in the ''''APP1/views/users/index.html.rb'''' > shows me a blank value. For this reason I can not even use the > conditional constructs and similar! > > > This is only an example, but it happens also when I use the REST > approach with API, and I think also in other cases when I make an > external request to APPs. It seems that RoR does not follow cookies. > > > So the question is: is it possible to get/share cookie or session > information between more RoR applications? > > > I use a Mac with OS "Snow Leopard" v10.6.5, Apache2 and Phusion > Passenger. > > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.