MaD wrote: > If you have a construct like this (all in the same file): > > # app/models/user.rb > class User < ActiveRecord::Base > # ... > end > > class UnassignedUser < User > def self.shout > puts "yeah" > end > end > > script/console will behave like this: > >> UnassignedUser.shout > NameError: uninitialized constant UnassignedUser (...) > >> User > => User(id: integer, login: string, email: string, password: string, > created_at: datetime, updated_at: datetime) > >> UnassignedUser.shout > yeah > => nil > > UnassignedUser gets only loaded when User is loaded. put it in its own > file and maybe add: > self.abstract_class = true
Separate file in the model directory? My objective is to avoid nil object errors when no user is logged in - i.e. when session[:user] is nil. However, I still need to call some instance methods on this object. Please suggest me how can I do this? > > other than that you can load it whenever you want via include or > require. -- 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

