OmniAuth创建中的DangerousAttributeError由ActiveRecord定义

时间:2013-02-28 14:07:23

标签: ruby-on-rails database ruby-on-rails-3 omniauth railscasts

请参阅此页面,因为我遇到同样的问题:DangerousAttributeError in OmniAuth Railscast Tutorial: create is defined by ActiveRecord

然而,对于rails来说还是比较新的,我不太确定如何从数据库中删除他们所说的字段。换句话说,在该帖子的任何地方都没有逐步简洁的描述方式。

下面的帖子实际上是一个正确的解决方案,但是当他写下来时,不清楚他所指的是什么:“rails g migration remove_silly_authentication_fields_which_should_not_be_there”不确定“silly_authentication_fields_which_should_not_be_there”到底是什么。

以下是我所指的帖子:

  

因此,只需完成问题,您就需要创建迁移   使用此命令:

     

rails g migration   remove_silly_authentication_fields_which_should_not_be_there

     

看起来像这样:

     

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

     

使用通常的方式运行它:

     

rake db:migration

     

或者您应该能够运行:

     

rake db:rollback

     

回滚刚刚对数据库所做的更改,并且:

     

rails d scaffold authentication

     

要删除所有文件,请运行:

     

rails g scaffold authentication user_id:integer provider:string   UID:字符串

     

手动执行其他操作

     

顺便说一下,我自己做了同样的事情。

1 个答案:

答案 0 :(得分: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生成迁移以使其保持一致

相关问题