2015-02-07 275 views
2

我正在与Omniauth认证的问题和轨道4由此我得到一个Rails ::加载ActiveModel ForbiddenAttributesError。加载ActiveModel的Rails :: ForbiddenAttributesError设计,Omniauth

我使用gem 'protected_attributes'如此强大的参数不应该是一个问题。

我的用户模型包含以下内容:

def self.from_omniauth(auth) 
    where(auth.slice(:provider, :uid)).first_or_create do |user| 
     user.username = auth.info.email 
     user.email = auth.info.email 
     user.password = Devise.friendly_token[0,20] 
     user.name = auth.info.name 
    end 
    end 

user.password在那里只是为了保持与现有设计身份验证系统的兼容性。

的AR错误表明该行:where(auth.slice(:provider, :uid)).first_or_create do |user|抛出的错误。

上述方法被调用来自:

class OmniauthCallbacksController < Devise::OmniauthCallbacksController 
    def mavenlink 
    @user = User.from_omniauth(request.env['omniauth.auth']) 
    service = @user.services.initialize_or_update_via_omniauth(request.env['omniauth.auth']) 
    if service && service.save 
     sign_in_and_redirect @user #this will throw if @user is not activated 
     set_flash_message(:notice, :success, :kind => "Mavenlink") if is_navigational_format? 
    else 
     redirect_to root_path, error: "Error signing in with Mavenlink credentials." 
    end 
    end 
end 

这是否与或没有,我不知道,但我也一直在运行此错误:

找不到有效的为路径映射“/认证/ mavenlink /回调”

也许没有关系,但我想我有以防万一。

任何帮助将不胜感激!

+0

把上面一行'那里(服务提供商:auth.provider,UID:auth.uid).first_or_create做|用户|'。这应该够了吧。 – 2015-02-07 20:08:58

+0

这样做,谢谢!为什么是这个问题? – Adam 2015-02-07 20:17:25

+0

[Rails 4.1.5 omniauth strong parameters]可能重复(http://stackoverflow.com/questions/25399414/rails-4-1-5-omniauth-strong-parameters) – zhurora 2015-09-10 13:39:27

回答

12

几周前我有同样的问题,并通过更改下面的行来修复它。基本上你应该明确地将参数传递给你的查询。

where(provider: auth.provider, uid: auth.uid).first_or_create do |user| 

你可以在这里找到一个Devise issue

+0

谢谢Justin,这真的很有帮助。但我仍不明白为什么这个问题没有出现在本地主机开发中,而只是开始在Heroku中出现。 – user3512640 2016-02-04 20:44:29

相关问题