Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8165679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:36:45+00:00 2026-06-06T19:36:45+00:00

I am getting this error when a new user account is getting created: ActiveRecord::StatementInvalid

  • 0

I am getting this error when a new user account is getting created:

ActiveRecord::StatementInvalid in SessionsController#create

SQLite3::SQLException: cannot start a transaction within a transaction: begin transaction

I am using koala and omniauth gem to autenticate and fetch users friends. Why cant I start two transactions, why does it rollback the friends migration?

How does one fix this?

This is my SessionController:

class SessionsController < ApplicationController
  def create
    user = User.from_omniauth(env['omniauth.auth'])
    session[:user_id] = user.id
    redirect_to root_url, notice: "Signed in!"
  end

This is my user model:

class User < ActiveRecord::Base
  has_many :friends

  def self.from_omniauth(auth)
    where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
      user.provider = auth["provider"]
      user.uid = auth["uid"]
      user.name = auth["info"]["name"] unless auth["info"].blank?
      user.first_name = auth["info"]["first_name"] unless auth["info"].blank?
      user.last_name = auth["info"]["last_name"] unless auth["info"].blank?
      user.image = auth["info"]["image"] unless auth["info"].blank?
      user.email = auth["info"]["email"] unless auth["info"].blank?
      user.gender = auth["extra"]["raw_info"]["gender"] if (!auth["extra"].blank? && !auth["extra"]["raw_info"].blank?)
      user.location = auth["extra"]["raw_info"]["location"]["name"] if (!auth["extra"].blank? && !auth["extra"]["raw_info"].blank? && !auth["extra"]["raw_info"]["location"].blank?)          
      user.token = auth["credentials"]["token"] unless auth["credentials"].blank?


        # highschool data
        user.highschool_name = auth["extra"]["raw_info"]["education"][0]["school"]["name"] if (!auth["extra"].blank? && !auth["extra"]["raw_info"]["education"][0]["school"].blank?)
        user.highschool_year = auth["extra"]["raw_info"]["education"][0]["year"]["name"] if (!auth["extra"].blank? && !auth["extra"]["raw_info"]["education"][0]["year"].blank?)
        # graduate school data
        user.graduateschool_name = auth["extra"]["raw_info"]["education"][1]["school"]["name"] if (!auth["extra"].blank? && !auth["extra"]["raw_info"]["education"][1]["school"].blank?)
        user.graduateschool_year = auth["extra"]["raw_info"]["education"][1]["year"]["name"] if (!auth["extra"].blank? && !auth["extra"]["raw_info"]["education"][1]["year"].blank?)
      user.add_friends  
      user.save!
      user
    end 
  end

  def add_friends
    facebook.get_connections("me", "friends").each do |hash|
      self.friends.where(:name => hash['name'], :uid => hash['id']).first_or_create
    end
  end

  private 

  def facebook
    @facebook ||= Koala::Facebook::API.new(token)
  end

end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:36:47+00:00Added an answer on June 6, 2026 at 7:36 pm

    The thing is, when the user hit the created method the method from_omniauth(auth) is checking if a user exists, if the user dosent exist its starting creating the user and grabbing all information from auth hash provided from Facebook. But before saving the user it calls the add_friends method, the user dosent exsist yet therefor the error!

    So you have to save the user first and then call the add_friends method

    And Sqlite3 is incapable of nested transactions!

    cheers!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying create a log specifically for logging user account activity. I created this
I am new to php and I am getting this error trying to load
I'm new to AS3 and I'm getting this error while trying to implement OO
I'm getting a compiler error for this line: Collections.sort(terms, new QuerySorter_TFmaxIDF(myInteger)); My customized Comparator
I keep getting this error when I try and view my register user page
Getting this error: 2009-09-03 12:44:02.307 xcodebuild[307:10b] warning: compiler 'com.apple.compilers.llvm.clang.1_0.analyzer' is based on missing compiler
Getting this error with jquery & jquery.form. Site has been live for awhile..upgraded to
Getting this error when try to add an item to my repositories/context: Collection has
I´m getting this error while trying to commit to a svn repository: svn: MKACTIVITY
Keep getting this error after inserting a subdatasheet into a query and trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.