ActiveRecord :: DangerousAttributeError destroy由Active Record定义

时间:2013-08-02 02:11:53

标签: ruby-on-rails activerecord omniauth ruby-on-rails-4

def create
            omniauth = request.env["omniauth.auth"]
            authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
            if authentication
              flash[:notice] = "Signed in successfully"
              sign_in_and_redirect(:user, authentication.user)
            elsif current_user
              current_user.authentication.create!(:provider => omniauth['provider'], :uid => omniauth['uid'])
              flash[:notice] = "Authentication successful"
              redirect_to authentication_url
            else
              user = User.new
              user.authentications.build(:provider => omniauth['provider'], :uid => omniauth['uid'])
              user.save!
              flash[:notice] = "Authentication successful"
              sign_in_and_redirect(:user, user)
            end
 end

这是用于创建twitter身份验证的代码。但是,在第13行,

user.authentications.build(:provider => omniauth['provider'], :uid => omniauth['uid'])
      user.save!

引发错误。

destroy is defined by Active Record

我在网上找不到任何帮助。 我正在关注railscast 236.Rails版本4.0.0,ruby版本2。 任何帮助将非常感激。

1 个答案:

答案 0 :(得分:3)

检查您的表格,确保您没有列名称,例如

index, create, destroy, delete