Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Rails Expert Help Please: ActiveRecord & Multiple Database connections
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
TamiNicks  
View profile  
 More options Oct 7 2012, 6:17 am
From: TamiNicks <tami.ni...@mamasource.com>
Date: Sun, 7 Oct 2012 03:17:58 -0700 (PDT)
Local: Sun, Oct 7 2012 6:17 am
Subject: Rails Expert Help Please: ActiveRecord & Multiple Database connections

Okay, so, first, complete newbie...which means that I would GREATLY
appreciate any help on this one.  Have been pulled, abruptly, in the middle
of trying to get something deployed, quickly...and, being a newbie, this is
difficult for me, but, based on everything that I've read, it actually is
fairly easy.

I've done this every which way but Sunday...this is my latest
attempt...take a look and let me know what steps I've missed...  Thank You!

I'm attempting to connect to first the prime database for this particular
web application, confirm or deny if a user's email address exists, and, if
it does exist, redirect the member over to one of our partner sites, while
also keeping a count on the 'users' table to ensure that the user doesn't
try to access the partner site more then 2x.

This is working just fine, no problems...  That's the good news...

If the application can't find the user on the application's prime database
site.  It now must connect to a secondary database and look for the user on
that database in the 'members' table.  If the email address does exist, it
increments the 'redirect_count' and then redirects the member over to one
of our partner sites.  If the member has reach the max allotted access to
the partner site, a message is flashed advising the user of such.

So, now for the code...note that the code provided, and the help needed, is
specific to connecting to, and validating (and updating) the members table.

This is the model file that I've created for the purpose of the connecting
to the secondary database, and validating  / updating the corresponding
members table.

*************************************************************************** *****************

class DealCore < ActiveRecord::Base

  conn2 = { :adapter => 'mysql',
    :encoding => 'utf8',
    :reconnect => 'true',
    :database => 'deals_qa',
    :username => 'xxxxxx',
    :password => 'xxxxxx',
    :host => 'xx.xx.xx.xx',
    :port => 'xxxx'
  }

  self.abstract_class = true

  establish_connection (conn2["deals_#{RAILS_ENV}"])

  class User < DealCore

    def clone_to_deals
      m = Users.find_by_email(@email)
      m.redirect_count += 1
      m.save
    end

    class << self
      def email_exists?(email)
        find_by_email(email)
      end

}

...and this is the code snippet that I created to call these 'secondary'
database classes:

if @user = DealCore::User.email_exists?(@email)
                member = @user.clone_to_deals
                @Redirect_Flag = [0,1,2].include? member.redirect_count
                @Costco_Flag = true
              end

Little help...pretty please!

Thanks!

Tami


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »