I am newbie to rail. Trying to develop social networking site so working with railspace application. Everything is working fine but I stuck in the problem when i am giving the authorization tocken to the user to remember him/her. My Error and controller code is below Error:- private method `gsub'' called for 4:Fixnum C:/Users/Amir/Downloads/IR/ruby/lib/ruby/1.8/cgi.rb:342:in `escape'' C:/Users/Amir/Downloads/IR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/cgi_ext/cookie.rb:73:in `to_s'' C:/Users/Amir/Downloads/IR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/cgi_ext/cookie.rb:73:in `collect'' C:/Users/Amir/Downloads/IR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/cgi_ext/cookie.rb:73:in `to_s'' C:/Users/Amir/Downloads/IR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/cookies.rb:80:in `set_cookie'' C:/Users/Amir/Downloads/IR/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/cookies.rb:65:in `[]='' app/controllers/user_controller.rb:27:in `login'' user_controller if request.get? @user = User.new(:remember_me => cookies[:remember_me] || "0") elsif param_posted?(:user) @user = User.new(params[:user]) user = User.find_by_screen_name_and_password(@user.screen_name, @user.password) if user user.login!(session) if @user.remember_me == "1" cookies[:remember_me] = { :value => "1", :expires => 10.years.from_now } user.authorization_token = user.id user.save! cookies[:authorization_token] = { :value => user.authorization_token, :expires => 10.years.from_now } else cookies.delete(:remember_me) cookies.delete(:authorization_token) end flash[:notice] = "User #{user.screen_name} logged in!" redirect_to_forwarding_url else @user.clear_password! flash[:notice] = "Invalid screen name/password combination" end end end Please do the needful. I don''t have much time, I need to deliver this project in my college. Thanks Amir -- 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-/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.
Priya D.
2012-Apr-25 09:06 UTC
Re: showing error (gsub) when switching from session to cookies
Can you pls provide your controller with line number? -- 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-/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.
Amir Z.
2012-Apr-25 10:15 UTC
Re: showing error (gsub) when switching from session to cookies
Please find my login code below. def login if request.get? @user = User.new(:remember_me => cookies[:remember_me] || "0") elsif param_posted?(:user) @user = User.new(params[:user]) user = User.find_by_screen_name_and_password(@user.screen_name, @user.password) if user user.login!(session) if @user.remember_me == "1" cookies[:remember_me] = { :value => "1", :expires => 10.years.from_now } user.authorization_token = user.id user.save! cookies[:authorization_token] = { (line no. 27) :value => user.authorization_token, (line no. 28) :expires => 10.years.from_now } (line no. 29) else cookies.delete(:remember_me) cookies.delete(:authorization_token) end flash[:notice] = "User #{user.screen_name} logged in!" redirect_to_forwarding_url else @user.clear_password! flash[:notice] = "Invalid screen name/password combination" end 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-/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.
Colin Law
2012-Apr-25 10:25 UTC
Re: Re: showing error (gsub) when switching from session to cookies
On 25 April 2012 11:15, Amir Z. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Please find my login code below. > > def login > if request.get? > @user = User.new(:remember_me => cookies[:remember_me] || "0") > elsif param_posted?(:user) > @user = User.new(params[:user]) > user = User.find_by_screen_name_and_password(@user.screen_name, > @user.password) > if user > user.login!(session) > if @user.remember_me == "1" > cookies[:remember_me] = { :value => "1", > :expires => 10.years.from_now } > user.authorization_token = user.id > user.save! > cookies[:authorization_token] = { (line no. 27) > :value => user.authorization_token, (line no. 28) > :expires => 10.years.from_now } (line no. 29)What is the path and file name that code is in? Check very carefully that you post the correct name, do not just type what you /think/ it is. Colin -- 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.
Frederick Cheung
2012-Apr-25 10:52 UTC
Re: showing error (gsub) when switching from session to cookies
On Apr 25, 5:15 am, "Amir Z." <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Please find my login code below. >> cookies[:authorization_token] = { (line no. 27) > :value => user.authorization_token, (line no. 28) > :expires => 10.years.from_now } (line no. 29)Cookie values should be strings, not integers. Also since you''ve set authoization_token to just be the user id, this allows any user to log into as any other user just be modifying the value of this cookie and guessing a user_id Fred> else > cookies.delete(:remember_me) > cookies.delete(:authorization_token) > end > flash[:notice] = "User #{user.screen_name} logged in!" > redirect_to_forwarding_url > else > @user.clear_password! > flash[:notice] = "Invalid screen name/password combination" > end > end > end > > -- > Posted viahttp://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-/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.
Colin Law
2012-Apr-25 10:57 UTC
Re: Re: showing error (gsub) when switching from session to cookies
On 25 April 2012 11:52, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Apr 25, 5:15 am, "Amir Z." <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Please find my login code below. >> > > >> cookies[:authorization_token] = { (line no. 27) >> :value => user.authorization_token, (line no. 28) >> :expires => 10.years.from_now } (line no. 29) > > Cookie values should be strings, not integers. Also since you''ve set > authoization_token to just be the user id, this allows any user to log > into as any other user just be modifying the value of this cookie and > guessing a user_idWhy is it I only know the answers to the easy questions I wonder. Colin -- 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.
Amir Z.
2012-Apr-25 12:22 UTC
Re: showing error (gsub) when switching from session to cookies
I got the point. Thank you so much Colin. Now code is working fine. Problem was that I was not using the hashing algorithm for authorization_token. It was taking the user.id as an authorization_token. As I apply the hashing algorithm to it. Hashing generates authorization token as a string. Problem Solved :) Thanks Colin Have a colorful day. Regards Amir -- 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-/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.
Colin Law
2012-Apr-25 12:31 UTC
Re: Re: showing error (gsub) when switching from session to cookies
On 25 April 2012 13:22, Amir Z. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I got the point. > > Thank you so much Colin. > > Now code is working fine. Problem was that I was not using the hashing > algorithm for authorization_token. It was taking the user.id as an > authorization_token. > > As I apply the hashing algorithm to it. Hashing generates authorization > token as a string. > > Problem Solved :) > > Thanks ColinOk, even though I only manage to answer the easy questions I get the credit for the more difficult ones. Excellent :) You might like to thank Fred too since it was he that provided the answer. Colin -- 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.
Amir Z.
2012-Apr-25 13:04 UTC
Re: showing error (gsub) when switching from session to cookies
Thank you Fred. Excellent work. Your ideas my effort makes the code workable :) Hope I will get the help in further problems as I am new to rails.:) Thanks Amir -- 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-/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.