【问题标题】:DangerousAttributeError in OmniAuth create is defined by ActiveRecordOmniAuth 创建中的 DangerousAttributeError 由 ActiveRecord 定义
【发布时间】:2013-02-28 14:07:22
【问题描述】:

请看这个页面,因为我有同样的问题: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 迁移 remove_silly_authentication_fields_which_should_not_be_there

看起来像这样:

类 DropSillyControllerAttributes

并使用通常的方式运行它:

rake db:迁移

或者你应该能够运行:

rake db:回滚

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

rails d 脚手架身份验证

要删除所有文件,然后运行:

rails g 脚手架身份验证 user_id:integer provider:string uid:字符串

然后手动做其他事情

顺便说一句,我自己也做过同样的事情。

【问题讨论】:

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


    【解决方案1】:

    它告诉您创建迁移以删除有问题的字段,然后运行迁移

    为了更清楚:

    运行这个命令:

    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 生成迁移以使其一致

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多