I saw a post on creating user Management Using Salted Hash Login Generator. I followed the steps, but I cannot get it to work. I keep getting a nil the troublesome code is in the plunge_controller.rb: def list @plunge_pages, @plunges = paginate :plunges, :conditions => [''user_id = ?'', @session[''user''].id] end This gives a "Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id" My plunge.rb model starts like this: class Plunge < ActiveRecord::Base belongs_to :user, :class_name => "User", :foreign_key => "user_id" and my user,rb like this: class User < ActiveRecord::Base has_many :plunges, :class_name => "User", :foreign_key => "user_id" ... I can get it to work by hardcoding the user id like this: @plunge_pages, @plunges = paginate :plunges, :conditions => ''user_id 1'' Anyone who can help? -- 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 -~----------~----~----~----~------~----~------~--~---
Jan Ask wrote:> I saw a post on creating user Management Using Salted Hash Login > Generator. I followed the steps, but I cannot get it to work. I keep > getting a nil > > the troublesome code is in the plunge_controller.rb: > def list > @plunge_pages, @plunges = paginate :plunges, :conditions => [''user_id > = ?'', @session[''user''].id] > end > > This gives a "Called id for nil, which would mistakenly be 4 -- if you > really wanted the id of nil, use object_id" > > My plunge.rb model starts like this: > class Plunge < ActiveRecord::Base > belongs_to :user, > :class_name => "User", > :foreign_key => "user_id" > > and my user,rb like this: > class User < ActiveRecord::Base > has_many :plunges, > :class_name => "User", > :foreign_key => "user_id" > > ... > I can get it to work by hardcoding the user id like this: > @plunge_pages, @plunges = paginate :plunges, :conditions => ''user_id > 1'' > > Anyone who can help?@session[''user''] is returning nil. (You knew this, right?) The question is why. Here are some things to check: * Are sessions working? They usually require some configuration, esp. if they are stored in the database. If you have just dropped this library into a new Rails Application check this out first. * Is the session being set properly? Check your controllers. If you cannot find a place where @session[''user''] = <something> you have a problem (Note: this may have come with the library code) * Is the browser/test case your using preserving sessions between calls? I cannot tell you the number of times a stale browser cache in Fire Fox or a test case that is not session aware has blown my whole day. As a final thought, a lot of these data persistence problems are very difficult to track down because there is no way to trace the execution path through the program. We MUST wait for the client to make a second request with the right data. To help me with this I have a debug template that I use for all my pages. The template contains a button at the bottom that will pop up a window which lists debug(@user), debug(params), debug(session), and debug(flash). Very helpful for these types of things. -- 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 -~----------~----~----~----~------~----~------~--~---
Hi John, Thanks for taking the time to help me. Your comments put me on the right track. I did some hours of debugging and decided to rewrite the thing as: def list @plunges = Plunge.find:all, :conditions => ["user_id = ?", session[:user_id]] end My login controller looks like this: def login session[:user_id] = nil if request.post? user = User.authenticate(params[:name], params[:password]) if user session[:user_id] = user.id ... No matter what I do, I cannot get @session[''user''].id to be anything other than nil, so I guess that session[:user_id] is an ok replacement :) Anyway, Thanks again for your help. Jan John Miller wrote:> Jan Ask wrote: >> I saw a post on creating user Management Using Salted Hash Login >> Generator. I followed the steps, but I cannot get it to work. I keep >> getting a nil >> >> the troublesome code is in the plunge_controller.rb: >> def list >> @plunge_pages, @plunges = paginate :plunges, :conditions => [''user_id >> = ?'', @session[''user''].id] >> end >> >> This gives a "Called id for nil, which would mistakenly be 4 -- if you >> really wanted the id of nil, use object_id" >> >> My plunge.rb model starts like this: >> class Plunge < ActiveRecord::Base >> belongs_to :user, >> :class_name => "User", >> :foreign_key => "user_id" >> >> and my user,rb like this: >> class User < ActiveRecord::Base >> has_many :plunges, >> :class_name => "User", >> :foreign_key => "user_id" >> >> ... >> I can get it to work by hardcoding the user id like this: >> @plunge_pages, @plunges = paginate :plunges, :conditions => ''user_id >> 1'' >> >> Anyone who can help? > > @session[''user''] is returning nil. (You knew this, right?) The question > is why. Here are some things to check: > > * Are sessions working? They usually require some configuration, esp. > if they are stored in the database. If you have just dropped this > library into a new Rails Application check this out first. > > * Is the session being set properly? Check your controllers. If you > cannot find a place where @session[''user''] = <something> you have a > problem (Note: this may have come with the library code) > > * Is the browser/test case your using preserving sessions between calls? > I cannot tell you the number of times a stale browser cache in Fire Fox > or a test case that is not session aware has blown my whole day. > > As a final thought, a lot of these data persistence problems are very > difficult to track down because there is no way to trace the execution > path through the program. We MUST wait for the client to make a second > request with the right data. To help me with this I have a debug > template that I use for all my pages. The template contains a button at > the bottom that will pop up a window which lists debug(@user), > debug(params), debug(session), and debug(flash). Very helpful for these > types of things.-- 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 -~----------~----~----~----~------~----~------~--~---