DangerousAttributeError在OmniAuth Railscast教程:创建由ActiveRecord的定义 [英] DangerousAttributeError in OmniAuth Railscast Tutorial: create is defined by ActiveRecord

查看:129
本文介绍了DangerousAttributeError在OmniAuth Railscast教程:创建由ActiveRecord的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看了<一href="http://stackoverflow.com/questions/7718651/activerecorddangerousattributeerror">ActiveRecord::DangerousAttributeError和SO其他类似的主题,但他们不解决同样的问题。

I've looked at ActiveRecord::DangerousAttributeError and other similar threads on SO, but they don't address the same issue.

我下面的omniauth教程:<一href="http://railscasts.com/episodes/235-omniauth-part-1?view=asciicast">http://railscasts.com/episodes/235-omniauth-part-1?view=asciicast

I'm following the omniauth tutorial: http://railscasts.com/episodes/235-omniauth-part-1?view=asciicast

我能够通过OAuth的认证与Twitter,并返回用户的数据(验证)。问题是,我不能创建,因为此错误消息/保存在数据库(sqlite3的)。

I'm able to authenticate via oauth with Twitter and return the user's data (auth). The problem is that I'm not able to create/save it in the database (sqlite3) because of this error message.

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

我如何工作,过去这个错误?谷歌搜索在本网站和其他人并不能帮助我了解发生了什么,以解决它回事。谢谢

How do I work past this error? Googling on this site and others doesn't help me understand what's going on in order to fix it. Thanks

推荐答案

ActiveRecord的警告你,你的一些数据库的属性名称(创建等)与冲突通过的ActiveRecord /红宝石提供的实例方法的名称。

Activerecord is warning you that some of your database attribute names (create etc.) clash with the names of instance methods provided by activerecord/ruby.

由于铁轨将另外创建这些名称的实例方法来访问属性,这种冲突来引起很奇怪的事情发生。因此,活动记录会引发一个异常提醒你,这是发生

Since rails would otherwise create instance methods of those names to access attributes, such a clash used to cause really weird things to happen. Thus active record raises an exception to warn you that this is happening

这篇关于DangerousAttributeError在OmniAuth Railscast教程:创建由ActiveRecord的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆