Jeremy,

Here's the code as I originally had it (and have returned to). Is this what
you were suggesting?

    def register
        @title = "Register with SteamCode"
        # Make sure we're getting here from a post request.
        if request.post?
            # Check the login and password.
            # if we find the Account based on the login and password. If we
find it
            # we'll save the login ID in the session variable and we can use
that
            # to show if the Account is currently logged in or not. If we
can't
            # find the Account, we'll set the flash message, set the session
to nil
            # and just stay on this page.
            if Account.find(:login => request[:loginID])

                # This user already exists. Set the flash message for them
to
                # try again.
                flash[:message] = "Login #{request[:loginID]} already used.
Please select another."

                # Stay on the register page.
                redirect Rs(:register)
            else
                # This account does not exist. Grab the loginID, the
password,
                # and the email and create a new Account with them.
                loginID = request[:loginID]
                password = request[:password]
                email = request[:email]

                # Log the new user (a real application wouldn't probably
print
                # the password out though).
                Ramaze::Log.debug "New User Added: loginID = #{loginID}
password = #{password} email = #{email}"

                # Create the account with the login, password, and email
given.
                Account.create(:login => loginID, :password => password,
:email => email)

                # Redirect to the login page.
                redirect Rs(:login)
            end
        end
    end

Scott

On Tue, Apr 14, 2009 at 7:06 PM, Scott LaBounty <[email protected]> wrote:

> Jeremy,
>
> That was my original approach. I was asking on the ramaze list if that was
> "normal" way to do it and it was suggested that it might work better just to
> do it and catch the exception. This causes only a single call to the
> database rather than two. I'm thinking of going back that way as it seems
> like it might be more clear and the overhead (particularly in this case)
> only marginal.
>
> Scott
>
>
> On Tue, Apr 14, 2009 at 4:37 PM, Clive Crous <[email protected]>wrote:
>
>>
>> 2009/4/14 Scott LaBounty <[email protected]>:
>> > guess I'm not sure which. May be easiest to just try
>> > it and see.
>>
>> Just a thought though: have you considered simply checking if the
>> account already exists yourself before calling create?
>>
>> Which adapter are you using though, as long as their transactions are
>> ACID you can check as much as you like beforehand ;)
>>
>> >>
>>
>
>
> --
> Scott
> http://steamcode.blogspot.com/
>



-- 
Scott
http://steamcode.blogspot.com/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sequel-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/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to