I''d like to be able to save sessions in a separate database. I created the following model below in session.rb: class Session < ActiveRecord::Base self.abstract_class = true establish_connection :userdb end I seem to be missing something however, as the server still tries to find the sessions table in the default database and not in the one I label as :userdb in my database.yml. What may that be? Thanks in advance, -Al --~--~---------~--~----~------------~-------~--~----~ 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, Al wrote:> class Session < ActiveRecord::Base > self.abstract_class = true > establish_connection :userdb > end > > I seem to be missing something however, as the server still tries to > find > the sessions table in the default database and not in the one I label as > :userdb in my database.yml. What may that be?According to <http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M001075> you must write something like this: establish_connection( :adapter => "mysql", :host => "localhost", :username => "myuser", :password => "mypass", :database => "somedatabase") A symbol is not enough. Lutz -- 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 -~----------~----~----~----~------~----~------~--~---
Actually, connecting to this database works from the console. That is, doing a simple Session.find(1) will display the right results. However, rails isn''t even referring to this model to know which database to connect to. So, what I think is lacking is something that connects rails'' use of the actual session to the Session model that I created. On 8/21/07, Lutz Horn <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hi, > > Al wrote: > > class Session < ActiveRecord::Base > > self.abstract_class = true > > establish_connection :userdb > > end > > > > I seem to be missing something however, as the server still tries to > > find > > the sessions table in the default database and not in the one I label as > > :userdb in my database.yml. What may that be? > > According to > > <http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M001075> > > you must write something like this: > > establish_connection( > :adapter => "mysql", > :host => "localhost", > :username => "myuser", > :password => "mypass", > :database => "somedatabase") > > A symbol is not enough. > > Lutz > -- > 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 -~----------~----~----~----~------~----~------~--~---
William Pratt
2007-Aug-21 13:46 UTC
Re: ActiveRecord Store of sessions in a separate database
Using a symbol works if the connection information is in database.yml. You supply the name of the connection only, allowing you to keep all database connections defined in one locaation. Lutz Horn wrote:> Hi, > > Al wrote: > >> class Session < ActiveRecord::Base >> self.abstract_class = true >> establish_connection :userdb >> end >> >> I seem to be missing something however, as the server still tries to >> find >> the sessions table in the default database and not in the one I label as >> :userdb in my database.yml. What may that be? >> > > According to > > <http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M001075> > > you must write something like this: > > establish_connection( > :adapter => "mysql", > :host => "localhost", > :username => "myuser", > :password => "mypass", > :database => "somedatabase") > > A symbol is not enough. > > Lutz >-- Sincerely, William Pratt http://www.billpratt.net billp-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
William Pratt
2007-Aug-21 13:51 UTC
Re: ActiveRecord Store of sessions in a separate database
I believe you need the following in your environment.rb config.action_controller.session_store = Session You have to supply the name of your class that you wish to use. Hope this helps ya. Al wrote:> I''d like to be able to save sessions in a separate database. > > I created the following model below in session.rb: > > class Session < ActiveRecord::Base > self.abstract_class = true > establish_connection :userdb > end > > I seem to be missing something however, as the server still tries to > find the sessions table in the default database and not in the one I > label as :userdb in my database.yml. What may that be? > > Thanks in advance, > > -Al > > >-- Sincerely, William Pratt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
That didn''t seem to work as I got a load_missing_constant'': uninitialized constant Session when ran server. On 8/21/07, William Pratt <billp-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org> wrote:> > > I believe you need the following in your environment.rb > > config.action_controller.session_store = Session > > You have to supply the name of your class that you wish to use. Hope > this helps ya. > > Al wrote: > > I''d like to be able to save sessions in a separate database. > > > > I created the following model below in session.rb: > > > > class Session < ActiveRecord::Base > > self.abstract_class = true > > establish_connection :userdb > > end > > > > I seem to be missing something however, as the server still tries to > > find the sessions table in the default database and not in the one I > > label as :userdb in my database.yml. What may that be? > > > > Thanks in advance, > > > > -Al > > > > > > > -- > Sincerely, > > William Pratt > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
William Pratt
2007-Aug-21 14:16 UTC
Re: ActiveRecord Store of sessions in a separate database
you will have to require it first since rails will not have loaded your class yet. just use a require above that line like:'' require File.join(File.dirname(__FILE__), ''app/models/session.rb'') Al wrote:> That didn''t seem to work as I got a > > load_missing_constant'': uninitialized constant Session > > when ran server. > > > On 8/21/07, *William Pratt * <billp-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org > <mailto:billp-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org>> wrote: > > > I believe you need the following in your environment.rb > > config.action_controller.session_store = Session > > You have to supply the name of your class that you wish to use. Hope > this helps ya. > > Al wrote: > > I''d like to be able to save sessions in a separate database. > > > > I created the following model below in session.rb: > > > > class Session < ActiveRecord::Base > > self.abstract_class = true > > establish_connection :userdb > > end > > > > I seem to be missing something however, as the server still tries to > > find the sessions table in the default database and not in the one I > > label as :userdb in my database.yml. What may that be? > > > > Thanks in advance, > > > > -Al > > > > > > > -- > Sincerely, > > William Pratt > > > > > > > > >-- Sincerely, William Pratt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Odd.. After adding that require line, I get the following error when launching script/server: => Booting Mongrel (use ''script/server webrick'' to force WEBrick) => Rails application starting on http://0.0.0.0:3412 => Call with -d to detach => Ctrl-C to shutdown server ** Starting Mongrel listening at 0.0.0.0:3412 ** Starting Rails with development environment... Exiting /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/mongrel.rb:15: warning: already initialized constant OPTIONS /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/mongrel.rb:18: undefined method `options'' for []:Array (NoMethodError) from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in `gem_original_require'' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in `require'' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require'' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in `new_constants_in'' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:495:in `require'' from /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3 /lib/commands/server.rb:39 from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'' from ./script/server:3 On 8/21/07, William Pratt <billp-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org> wrote:> > you will have to require it first since rails will not have loaded your > class yet. just use a require above that line like:'' > > require File.join(File.dirname(__FILE__), ''app/models/session.rb'') > > Al wrote: > > That didn''t seem to work as I got a > > load_missing_constant'': uninitialized constant Session > > when ran server. > > > On 8/21/07, William Pratt <billp-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org> wrote: > > > > > > I believe you need the following in your environment.rb > > > > config.action_controller.session_store = Session > > > > You have to supply the name of your class that you wish to use. Hope > > this helps ya. > > > > Al wrote: > > > I''d like to be able to save sessions in a separate database. > > > > > > I created the following model below in session.rb: > > > > > > class Session < ActiveRecord::Base > > > self.abstract_class = true > > > establish_connection :userdb > > > end > > > > > > I seem to be missing something however, as the server still tries to > > > find the sessions table in the default database and not in the one I > > > label as :userdb in my database.yml. What may that be? > > > > > > Thanks in advance, > > > > > > -Al > > > > > > > > > > > -- > > Sincerely, > > > > William Pratt > > > > > > > > > > > > > > > > -- > Sincerely, > > William Pratt > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Resolved this after updating my gems, and then running script/about and I saw that it wasn''t loading the file path correctly. So, my new problem is when reading session.rb, it says "uninitialized constant ActiveRecord". On 8/21/07, Al <broohaha-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Odd.. After adding that require line, I get the following error when > launching script/server: > > => Booting Mongrel (use ''script/server webrick'' to force WEBrick) > => Rails application starting on http://0.0.0.0:3412 > => Call with -d to detach > => Ctrl-C to shutdown server > ** Starting Mongrel listening at 0.0.0.0:3412 > ** Starting Rails with development environment... > Exiting > /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/mongrel.rb:15: > warning: already initialized constant OPTIONS > /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/mongrel.rb:18: > undefined method `options'' for []:Array (NoMethodError) > from > /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in > `gem_original_require'' > from > /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in `require'' > from /usr/local/lib/ruby/gems/1.8/gems/activesupport- 1.4.2/lib/active_support/dependencies.rb:495:in > `require'' > from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:342:in > `new_constants_in'' > from /usr/local/lib/ruby/gems/1.8/gems/activesupport- 1.4.2/lib/active_support/dependencies.rb:495:in > `require'' > from /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3 > /lib/commands/server.rb:39 > from > /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in > `gem_original_require'' > from > /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'' > from ./script/server:3 > > > > On 8/21/07, William Pratt <billp-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org> wrote: > > > > you will have to require it first since rails will not have loaded your > > class yet. just use a require above that line like:'' > > > > require File.join(File.dirname(__FILE__), ''app/models/session.rb'') > > > > Al wrote: > > > > That didn''t seem to work as I got a > > > > load_missing_constant'': uninitialized constant Session > > > > when ran server. > > > > > > On 8/21/07, William Pratt <billp-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org> wrote: > > > > > > > > > I believe you need the following in your environment.rb > > > > > > config.action_controller.session_store = Session > > > > > > You have to supply the name of your class that you wish to use. Hope > > > this helps ya. > > > > > > Al wrote: > > > > I''d like to be able to save sessions in a separate database. > > > > > > > > I created the following model below in session.rb: > > > > > > > > class Session < ActiveRecord::Base > > > > self.abstract_class = true > > > > establish_connection :userdb > > > > end > > > > > > > > I seem to be missing something however, as the server still tries to > > > > find the sessions table in the default database and not in the one I > > > > label as :userdb in my database.yml. What may that be? > > > > > > > > Thanks in advance, > > > > > > > > -Al > > > > > > > > > > > > > > > -- > > > Sincerely, > > > > > > William Pratt > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > Sincerely, > > > > William Pratt > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---