2012-02-15 158 views
1

我遇到了一個奇怪的情況發生在我能夠通過Omniauth從本地運行時通過Omniauth讀取並保存信息的地方,但是當我將確切代碼推送到Heroku時,下面的錯誤(來自我的日誌)關於列first_name。OmniAuth ActiveRecord錯誤推向Heroku

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,提供者等全部保存到數據庫)。

讓我完全困惑的事情是,這段代碼在本地工作 - 所以我收集我正在從「raw_info」部分正確請求數據。

我已經確認我已經在Heroku上運行過我的遷移,並且已經像其他Q &一樣建議 - 還使用'heroku restart'來確保數據庫列在應用程序中被選中。

這是我的Gemfile我OmniAuth項:

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

我運行的Rails 3.1.3和Postgres 9.1.2本地。我使用我認爲運行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

你看到了什麼,如果你檢查通過控制檯水族模型。它有這個專欄嗎? – 2012-02-15 12:42:06

+0

可惜我不能看到實際的PG數據庫,因爲我在Heroku上的免費版本。這就是說我的遷移上下工作正常,沒有錯誤,所以我相信這些列正在創建。 – xander 2012-02-16 08:59:58

+0

通過控制檯看看。 heroku運行控制檯; Aquarist.new – 2012-02-16 09:24:39

回答

0

弄清楚它是什麼...一個拙劣的遷移文件。沿線某處我做了(傻)修改原始遷移文件,並在我的開發環境中正常運行,但忘了在線反向的變化。

不會再這樣做,我可以用8個小時左右回到我的生活做。 :)