Bej*_*rge 13 ruby rubygems ruby-on-rails devise omniauth
我已经按照本教程(http://railscasts.com/episodes/236-omniauth-part-2)使用OmniAuth和Devise创建facebook登录,我收到此错误:在我的路由中自动加载常量用户时检测到循环依赖性. RB
devise_for :users , :controllers => {:registrations => 'registrations'}
Run Code Online (Sandbox Code Playgroud)
registrations_controller.rb
Class RegistrationsController < Devise::RegistrationsController
def create
super
session[:omniauth] = nil unless @user.new_record?
end
private
def build_resource(*args)
super
if session["devise.omniauth"]
@user.apply_omniauth(session["devise.omniauth"])
session["devise.omniauth"] = nil
end
end
end
Run Code Online (Sandbox Code Playgroud)
这是来自AuthenticationsController的我的创建方法
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.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid'])
flash[:notice] = "Authentication successful."
redirect_to authentications_url
else
user = User.new
user.apply_omniauth(omniauth)
if user.save
flash[:notice] = "Signed in successfully."
sign_in_and_redirect(:user, user)
else
session[:omniauth] = omniauth.except('extra')
redirect_to new_user_registration_url
end
end
end
Run Code Online (Sandbox Code Playgroud)
Jon*_*han 12
你被registrations_controller.rb保存到哪里了?位置很重要.我发现我在保存它时犯了一个错误app/controllers/devise/..它只需要保存在app/controllers/.例如:
app/controllers/registrations_controller.rb
此外,config/routes.rb路线应定义为:
devise_for :users, controllers: { registrations: 'registrations' }
很多宝石在 Rails 4 上开始损坏,这都是由于控制器中的卸载问题造成的。 https://github.com/flyerhzm/switch_user/issues/34 https://github.com/thoughtbot/high_Voltage/issues/68 https://github.com/thoughtbot/clearance/issues/276 等等
您应该检查哪个 gem 造成了问题。一旦您知道:1)检查该 gem 的未解决问题 2)如果该问题存在并已修复,请确保您已修复该问题,否则更新该 gem。3)如果没有,您可以创建一个问题并要求他们解决。4)如果你不想等待他们的修复,你可以形成gem并为其推送修复 https://github.com/cashins/email_preview/commit/b34a077a954b98bd086153fae8979ad142667555 所有修复都是相同的(从指定控制器中删除可卸载的)
希望能帮助到你。
如果没有什么可以帮助降级你的 Rails 版本。
| 归档时间: |
|
| 查看次数: |
28071 次 |
| 最近记录: |