gpt4 book ai didi

ruby-on-rails - OmniAuth 创建中的 DangerousAttributeError 由 ActiveRecord 定义

转载 作者:搜寻专家 更新时间:2023-10-30 23:15:14 24 4
gpt4 key购买 nike

请看这个页面,因为我有同样的问题: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”到底是什么。

这是我指的帖子:

So just to finish the question off you will need to create a migration using this command:

rails g migration remove_silly_authentication_fields_which_should_not_be_there

Which looks something like this:

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

And run it using the usual:

rake db:migration

Or alternatively you should be able to run:

rake db:rollback

To roll back the changes just made to the database and:

rails d scaffold authentication

To remove all the files, then run:

rails g scaffold authentication user_id:integer provider:string uid:string

And do the other stuff manually

I did exactly the same thing myself by the way.

最佳答案

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

为了更清楚:

运行这个命令:

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

关于ruby-on-rails - OmniAuth 创建中的 DangerousAttributeError 由 ActiveRecord 定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15137532/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com