我在 SO 上查看了ActiveRecord::DangerousAttributeError和其他类似线程,但它们没有解决相同的问题。
我正在关注omniauth教程:http ://railscasts.com/episodes/235-omniauth-part-1?view=asciicast
我能够通过 oauth 与 Twitter 进行身份验证并返回用户的数据 (auth)。问题是由于此错误消息,我无法在数据库(sqlite3)中创建/保存它。
错误:
ActiveRecord::DangerousAttributeError in AuthenticationsController#create
create is defined by ActiveRecord
Rails.root: /beta/devise-omniauth1
Application Trace | Framework Trace | Full Trace
app/controllers/authentications_controller.rb:15:in `create'
Authentications_Controller:
def create
auth = request.env["omniauth.auth"]
current_user.authentications.create(:provider => auth['provider'], :uid => auth['uid'])
flash[:notice] = "Authentication successful."
redirect_to authentications_url
end
楷模:
class Authentication < ActiveRecord::Base
belongs_to :user
end
class User < ActiveRecord::Base
has_many :authentications
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
end
我该如何解决这个错误?在这个网站和其他网站上搜索并不能帮助我理解为了修复它发生了什么。谢谢