2013-02-28 78 views
1

定義請參閱此頁,因爲我有同樣的問題:DangerousAttributeError in OmniAuth Railscast Tutorial: create is defined by ActiveRecordDangerousAttributeError創建由ActiveRecord的

但是是相當新的軌道,我不是很確定爲如何刪除他們講的領域來自數據庫。換句話說,在這篇文章的任何地方都沒有描述一步一步簡潔的方式。

的後下其實是一個妥善的解決辦法,但目前還不清楚爲他指的是,當他寫下了:「軌摹遷移remove_silly_authentication_fields_which_should_not_be_there」不知道什麼是「silly_authentication_fields_which_should_not_be_there」正是。

這裏我指的帖子:

所以剛完成的問題關閉,您將需要在使用該命令創建遷移 :

軌摹遷移 remove_silly_authentication_fields_which_should_not_be_there

看起來像這樣:

class DropSillyControllerAttri butes <的ActiveRecord ::移民高清 變化 remove_column:認證,:指數 remove_column:認證,:創建 remove_column:認證,:摧毀年底結束

而且使用通常的運行它:

耙分貝:遷移

或者你也應該能夠運行:

耙分貝:回滾

回滾只是對數據庫所做的和變化:

軌d支架認證

要刪除所有文件,然後運行:

軌摹支架認證USER_ID:整數提供商:字符串 UID:字符串

,並做其他的東西手動

我的方式做同樣的事情自己。

回答

2

它告訴你創建遷移到刪除有問題的領域,然後運行遷移

,以使其更清晰:

運行此命令:

rails g migration drop_silly_controller_attributes 

該命令將在/ db/migratie /中創建一個帶有時間戳和該名稱的文件,如下所示:

2013121212312312_drop_silly_controller_attributes.rb 

打開該文件,並修改它看起來像這樣:

class DropSillyControllerAttributes < ActiveRecord::Migration 
    def change 
    remove_column :authentications, :index 
    remove_column :authentications, :create 
    remove_column :authentications, :destroy 
    end 
end 

那麼你就可以運行遷移做:

rake db:migrate 

這是令人困惑的,因爲如果你生成「remove_silly_authentication_fields_which_should_not_be_there」遷移該類應該是RemoveSillyAuthenticationFieldsWhichShouldNotBeThere,但它會說「DropSillyControllerAttributes」,因此您應該使用drop_silly_controller_attributes生成遷移以使其保持一致