Multiple Database write question

I am working on reconfiguring an app that we are about to release to
work tighter with another app that we already have. Both of these
apps are going to share a single users database that stores the
general information about the user such as login, password, name,
email and so forth. They also have app specific stuff that is
attributed to the user that is stored in the app’s own db. My
question is this, I have tried several ways to get a single object to
be created from data coming from different DB’s but could not get it
to work so i went about having a couple of different objects and
reworking the various actions to pull data from them. However I ran
into an issue that I can’t wrap my head around.

The User model has a establish_connection set to my shared users
database and I can read data all day long from it and everything
works fine, however when I go to allow the user to edit their profile
(change prefered language, or their email) the app hapily sends the
data to the controller, but the info is never saved into the
database. Looking through the logs nothing ever complains either.
Where things are really getting me is that on a different box, where
we have not made these changes yet if i go through the same process
the app reacts as it should. It is my understanding that when
connecting to another DB you do it in the model and than it should
connect and update what needs to be changed.

My controller looks like this:

def info
@updateuser = nil
@updateuser = User.find_first([“login = ?”, @user.login])
@updateuser.lastname = @params[:post][:lastname]
@updateuser.firstname= @params[:post][:firstname]
@updateuser.prefered_language = @params[:prefered_language]
notice = “”
if not @params[:post][:password].empty? and not @params[:post]
if @params[:post][:password] == @params[:post][:passwordbis]
@newuser.password = @params[:post][:password]
notice += “Your passwords don’t match!”
if not notice.empty?
flash[:notice] = notice
redirect_back_or_default :controller => “podcasts”
if not @updateuser.nil? and
flash[:notice] = _(‘account_prefs_saved’)
redirect_back_or_default :controller => “articles”
@user = @updateuser
else[:notice] = “An error occured while saving your preferences”
redirect_back_or_default :controller => “articles”

and my model has the following connection code in it:

establish_connection(:adapter => “mysql”,
:host => “localhost”,
:port => 3306,
:database => “GlobalUsers_development”,
:username => “root”,
:password => “root”)
set_table_name “users”

as you can see right now on my dev box I am connecting to my local
mysql instance as root so it shouldn’t be permission problems.

Do I need to establish a connection in the controller as well to
update this info? My understanding of the Various Howto’s that I have
found only mention putting the code in the model to connect.

Aslo I have tried to put the connection info in my database.yml file
but rails complains left and right when I try to access the app that
the database is not initialized.

thanks for all the help


Can someone please help me figure this out. I did some playing around
and if I change my below code to something like this:

@updateuser.update_attribute(:prefered_language, @params

and leave everything else alone it works for the most part except
that I lose my flash notice that everything was saved in the users
preferences. However If I leave it as it was it doesn’t work when
going after my new database but if the user table is in the existing
app database it works as it should. (proven by the current production
server of the app). I thought if I explicitly put a
in there it would work however it does not, no matter where I put a the @updateuser object does not update the
associated table for that user. I really would like to get it working
the way that I have it right now but would make the change if I
absolutely must, as like I said it worked before I switched to moving
the user info to a second database.

Any thoughts would be much appreciated.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs