1

ローカルで実行しているときにOmniauth経由でFacebookレスポンスから情報を読み込んで保存できるような状況が発生しましたが、正確なコードをHerokuにプッシュすると、カラムfirst_nameに関する(私のログから)来ています。私は、ユーザーの代わりに、用語「アクアリスト」を使用していヘロクに移動するときにOmniAuth ActiveRecordエラーが発生する

Processing by AdminController#index as HTML 
Rendered admin/list_users.html.erb within layouts/application (60.9ms) 
Completed 500 Internal Server Error in 163ms 

ActionView::Template::Error (undefined method `first_name' for #<Aquarist:0x00000001ee8>): 
:  <td>Nickname: <%= aquarist.nickname %> 
:  32:   Last: <%= aquarist.last_name %></td> 
:  29:  <td><%= aquarist.name %></td> 
:  31:   First: <%= aquarist.first_name %> 
:  34:  <td><%= aquarist.email %></td> 
:  28:  <td><%= image_tag(aquarist.image, :width => '20') %></td> 
:  33:  <td><%= aquarist.provider %></td> 

...私は、これは標準的な使用ではありません知っているが、私のユースケースのためには、もう少し理にかなっているようです。私は

ここomniauthからの私のFacebookのコールバックです...時間に戻ってそれを変更することがあります。

--- !ruby/hash:OmniAuth::AuthHash 
provider: facebook 
uid: '12456789' 
info: !ruby/hash:OmniAuth::AuthHash::InfoHash 
    email: [email protected] 
    name: Alex 
    first_name: Alex 
    last_name: Lastname 
    image: http://graph.facebook.com/123456789/picture?type=square 
    urls: !ruby/hash:Hashie::Mash 
    Facebook: http://www.facebook.com/profile.php?id=12456789 
credentials: !ruby/hash:Hashie::Mash 
    token: AACCCCb1i3ZALXEMfGxJtKZA 
    expires_at: 13378794564 
    expires: true 
extra: !ruby/hash:Hashie::Mash 
    raw_info: !ruby/hash:Hashie::Mash 
    id: '12456789' 
    name: Alex Lastname 
    first_name: Alex 
    last_name: Lastname 
    link: http://www.facebook.com/profile.php?id=12456789 
    gender: male 
    email: [email protected] 
    timezone: 11 
    locale: en_US 
    verified: true 
    updated_time: '2012-02-01T12:51:00+0000' 

あなたはとてもすべての余分を得ることを期待していない私は私のFacebookのプロフィールをロックダウンしてきた見ることができるように情報(例えば、関係の状態など)。

私は新しいユーザー(私の用語では「aquarists」)の基本的なプロフィールを構築しようとしています。これは、Facebookから共有することができる追加情報の一部を拾います。

これをローカルで実行すると、first_name、last_name、gender、localeなどを収集してデータベースに保存できます。

ここで私は、私はその後、(表中)このプロファイル情報を表示するには、このコードを使用していたプロファイル

def self.create_with_omniauth(auth) 
create! do |aquarist| 
    aquarist.provider  = auth["provider"] 
    aquarist.uid    = auth["uid"] 
    aquarist.name   = auth["info"]["name"] 
    aquarist.nickname  = auth["info"]["nickname"] 
    aquarist.email   = auth["info"]["email"] 
    aquarist.image   = auth["info"]["image"] 
    aquarist.first_name  = auth["extra"]["raw_info"]["first_name"] 
    aquarist.last_name  = auth["extra"]["raw_info"]["last_name"] 
    aquarist.user_location = auth["extra"]["raw_info"]["user_location"] 
    aquarist.user_hometown = auth["extra"]["raw_info"]["user_hometown"] 
    aquarist.age    = auth["extra"]["raw_info"]["age"] 
    aquarist.locale   = auth["extra"]["raw_info"]["locale"] 
    aquarist.gender   = auth["extra"]["raw_info"]["gender"] 
end 
end 

を書くために使用しているコードです:

<% @aquarists.each do |aquarist|%> 
<tr class="tbody"> 
    <td><%= aquarist.uid %></td> 
    <td><%= image_tag(aquarist.image, :width => '20') %></td> 
    <td><%= aquarist.first_name %></td> 
    ..and so on 

同一の情報は、私はこのコードをプッシュすると上記のようにアクティブなレコードエラーが発生します。

[raw_info] [extra]セクションから列を削除した場合、コードはHerokuで機能します(例:フルネーム、UID、プロバイダなどはすべてdbに保存されます)。

私が完全に混乱しているのは、このコードがローカルで動作していることです。そのため、「raw_info」セクションから正しくデータを要求しています。

私はHerokuでマイグレーションを実行したことを既に確認しています。他のいくつかのQ &のように、また、データベースの列がアプリケーションで確実にピックアップされるように 'heroku restart'を使用しました。

これは私のgemfileの私OmniAuthエントリです:私はRailsの3.1.3およびローカルpostgresの9.1.2を実行している

gem 'omniauth' 
gem 'omniauth-twitter' 
gem 'omniauth-facebook' 

。私はPG 8.xを実行すると信じている無料のHerokuデータベースを使用しています。ここで

は、特定の列を作成し、移行ファイルからの抜粋です:

def change 
    add_column("aquarists", "first_name", :text, :default => "") 
    add_column("aquarists", "last_name", :text, :default => "") 
    add_column("aquarists", "gender", :text, :default => "") 
    add_column("aquarists", "user_location", :text, :default => "") 
    add_column("aquarists", "user_relationships", :text, :default => "") 
    add_column("aquarists", "user_hometown", :text, :default => "") 
    add_column("aquarists", "age", :integer) 
    add_column("aquarists", "locale", :text, :default => "") 
    add_column("aquarists", "image", :text, :default => "") 
    add_column("aquarists", "timezone", :text, :default => "") 
    add_column("aquarists", "last_login", :datetime) 
end 

そして、これは私がHerokuのコンソールを実行したときに戻って来るものです:

$ heroku run console 
Running console attached to terminal... up, run.1 
Loading production environment (Rails 3.1.3) 
irb(main):001:0> Aquarist.new 
=> #<Aquarist id: nil, nickname: nil, name: nil, email: nil, created_at: nil, updated_at: nil, provider: nil, uid: nil, admin: false, age: nil, locale: "", image: "", timezone: "", last_login: nil, visits: nil> 
irb(main):002:0> 

起こっことができるものを上の任意の意見私のコードがHerokuを打っているとき?それはPostgresのバージョンの問題ですか?

+0

コンソールからAquaristモデルを調べるとどうなりますか?この列はありますか? –

+0

残念ながら私はherokuの無料版を使用しているため、実際のP​​Gデータベースは表示されません。それは、私の移行のアップ/ダウンがエラーなしで正常に動作し、カラムが作成されていると確信しています。 – xander

+0

コンソールから見てください。 herokuはコンソールを実行します。 Aquarist.new –

答えて

0

ボットされたマイグレーションファイルの内容を修正しました。行のどこかに、オリジナルのマイグレーションファイルを(愚かな)修正を加えて、自分の開発環境で正しく実行しましたが、オンラインで変更を取り消すのを忘れました。

もう一度やり直してはいけません。私の人生では8時間ほどかかります。 :)

関連する問題