When I try and access a cookie I have set instead of just returning the value it returns this string: login_username=email%40example.com; path I am trying to access it from my view using this code: <%= text_field_tag("login_username", @cookies[''login_username'']) %> Has anyone else had this problem? Does anyone know how I can just get it to return the value?
Oliver Legg wrote:> When I try and access a cookie I have set instead of just returning the > value it returns this string: > > login_username=email%40example.com; path> > I am trying to access it from my view using this code: > > <%= text_field_tag("login_username", @cookies[''login_username'']) %> > > Has anyone else had this problem? Does anyone know how I can just get > it to return the value?Try using the method "cookies" from the ActionController::Cookies mixin. http://rails.rubyonrails.com/classes/ActionController/Cookies.html From the view, you would have to write: controller.cookies[''...''] rgds Dema http://dema.ruby.com.br/
So would I write: sellers.cookies[''login_username''] My controller is called sellers and the cookie I am trying to access is called login_username. On 4 Jul 2005, at 14:20, Demetrius Nunes wrote:> Oliver Legg wrote: > >> When I try and access a cookie I have set instead of just >> returning the value it returns this string: >> login_username=email%40example.com; path>> I am trying to access it from my view using this code: >> <%= text_field_tag("login_username", @cookies[''login_username'']) %> >> Has anyone else had this problem? Does anyone know how I can just >> get it to return the value? >> > > Try using the method "cookies" from the ActionController::Cookies > mixin. > http://rails.rubyonrails.com/classes/ActionController/Cookies.html > > From the view, you would have to write: controller.cookies[''...''] > > rgds > Dema > http://dema.ruby.com.br/ > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Oliver Legg wrote:> So would I write: > > sellers.cookies[''login_username''] > > My controller is called sellers and the cookie I am trying to access is > called login_username.No, just: controller.cookies[''login_username''] #controller is a method from ActioView::Base to give your view access to the public parts of the current controller. Another good approach would be to make the #cookies method a helper method by writing: helper_method :cookies on your controller class. This way you would just say: cookies[''login_username''] Hope that helps, Dema http://dema.ruby.com.br/