Is it possible to access models when your in the console ? It seems like that is not possible and I need to create the classes within the console. Am I doing something wrong ? Stuart
After posting this question I went ahead and did some googling so I found the parameters NAME and DESCRIPTION but found I''m getting these errors: C:\InstantRails\rails_apps\r4rmusic>ruby script/console NAME Loading NAME environment. C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.1.4/lib/initializer.rb:168:in `read'':Errno::ENOENT: No such file or directory - ./script/../config/../config/../config/environments/NAME.rb>>C:\InstantRails\rails_apps\r4rmusic>ruby script/console DESCRIPTION Loading DESCRIPTION environment. C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.1.4/lib/initializer.rb:168:in `read'':Errno::ENOENT: No such file or directory - ./script/../config/../config/../config/environments/DESCRIPTION.rb So now that I think I know how to access the models and controllers from console, I seem to have a problem. Any ideas ? Stuart On 8/13/06, Dark Ambient <sambient@gmail.com> wrote:> Is it possible to access models when your in the console ? It seems > like that is not possible and I need to create the classes within the > console. Am I doing something wrong ? > > Stuart >
On Aug 13, 2006, at 11:35 AM, Dark Ambient wrote:> Is it possible to access models when your in the console ? It seems > like that is not possible and I need to create the classes within the > console. Am I doing something wrong ? > > Stuart > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/railsYes its possible. Actually thats pretty much the main point of script/console. In order to tell it what env you want to run in try this: $ script/console production OR $ script/console test OR $ script/console # this one will default to development env. Then your models are just available in the console. Am I missing something about your problem? -Ezra
My problem is that it seems within console the models are not available immediately. As an example I have a model name user.rb. Table is set up accordingly. I''m connected to the database. I open console and do: abe = User.new This won''t work as User is not recognized. I''m forced to define the class again in the console. class User end now i can add a new user . However the same goes for any methods that maybe defined within that model. Those also seem to need to be recreated in the console. My assumption was that when entering console all controllers and models (including the methods withing) would be immediately available. So what am I doing wrong ? Stuart On 8/13/06, Ezra Zygmuntowicz <ezmobius@gmail.com> wrote:> > On Aug 13, 2006, at 11:35 AM, Dark Ambient wrote: > > > Is it possible to access models when your in the console ? It seems > > like that is not possible and I need to create the classes within the > > console. Am I doing something wrong ? > > > > Stuart > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > Yes its possible. Actually thats pretty much the main point of > script/console. In order to tell it what env you want to run in try > this: > > > $ script/console production > > OR > > $ script/console test > > OR > > $ script/console # this one will default to development env. > > Then your models are just available in the console. Am I missing > something about your problem? > > -Ezra > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On Mon, 2006-08-14 at 07:54 -0600, Dark Ambient wrote:> My problem is that it seems within console the models are not > available immediately. > As an example I have a model name user.rb. Table is set up > accordingly. I''m connected to the database. > I open console and do: > > abe = User.new > > This won''t work as User is not recognized. > I''m forced to define the class again in the console. > class User > end > now i can add a new user . However the same goes for any methods that > maybe defined within that model. Those also seem to need to be > recreated in the console. > > My assumption was that when entering console all controllers and > models (including the methods withing) would be immediately available. > So what am I doing wrong ?---- $ script/console>> require "app/models/user.rb"Craig