0

I've spent a few hours on this so here I am. Starting with Ryans Railscast, I decided to add twitter login to my rails / devise app. I followed it for a bit, had issues and troubleshooted various issues until I got here: When clicking "Sign in with twitter", I am redirected there and upon return, I get the following issue:

ActiveRecord::StatementInvalid in Users::OmniauthCallbacksController#twitter

SQLite3::SQLException: no such column: users.provider: SELECT "users".* FROM "users" WHERE "users"."provider" = 'twitter' AND "users"."uid" = '20323034' ORDER BY "users"."id" ASC LIMIT 1

This issue is very close to this other stackoverflow problem, except they are using the facebook login rather than twitter. See top comment on top answer:

Devise, Omniauth and Facebook integration session error

Please advise, and thank you!

routes: devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks", :registrations => "registrations" } do

get "info/contact" get "info/about" get "info/landing" get "info/test" get '/users/sign_out' => 'devise/sessions#destroy'

root "info#landing" end

resources :events do resources :registrations end end

gemfile:

gem 'zurb-foundation'

gem 'devise'

gem 'omniauth-twitter'

gem 'omniauth'

gem 'oauth2'

Community
  • 1
  • 1
piratebroadcast
  • 291
  • 5
  • 15

1 Answers1

3

I will try to respond with a more thorough answer, but for starters this error is being thrown because you have not yet added columns to your User model to store the provider name (i.e. "twitter"). You also need to store the twitter access token, twitter uid, and twitter secret. The Facebook Omniauth only requires the provider, access_token, and uid columns, but Twitter needs to store a secret in addition to these.

What logic are you using in your controller?

From terminal, run the following migration: rails g migration AddTwitterColumnsToUsers

class AddTwitterColumnsToUsers < ActiveRecord::Migration
  def change
    add_column :users, :provider, :string
    add_column :users, :access_token, :string
    add_column :users, :uid, :string
    add_column :users, :twitter_secret, :string
  end
end

And then from terminal: rake db:migrate

Ryan Francis
  • 635
  • 6
  • 7
  • I moved this and it now resides in Controllers/Users/ Gist: https://gist.github.com/piratebroadcast/976ca80fbe0afb9e23ef If that looks good to you, I will run your migration. Will I have errors for non-oauth signups & Nil values? Thank you. – piratebroadcast Sep 25 '13 at 01:02
  • Ran it, now have this error: unknown attribute: name return registered_user else user = User.create(name:auth.info.name, provider:auth.provider, uid:auth.uid, email:auth.uid+"@twitter.com", – piratebroadcast Sep 25 '13 at 01:14
  • Do you have a "name" column in your user table? The method noted in the error is trying to save the user's name to a column called "name". Where is the following method? User.create(name:auth.info.name, provider:auth.provider... – Ryan Francis Sep 25 '13 at 05:17