I've followed this tutorial (http://railscasts.com/episodes/236-omniauth-part-2) for creating facebook login with OmniAuth and Devise and I get this error: Circular dependency detected while autoloading constant User in my routes.rb
我遵循了本教程(http://railscasts.com/episode des/236-omniauth-part-2),使用OmniAuth创建facebook登录,并设计了这个错误:在我的routes.rb中自动检测到循环依赖
devise_for :users , :controllers => {:registrations => 'registrations'}
registrations_controller.rb
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
and here's my create method from AuthenticationsController
这是我从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
8 个解决方案
#1
11
Where was your registrations_controller.rb
saved to? The location is important. I found that I was making a mistake saving it to app/controllers/devise/.
. It simply needed to be saved in app/controllers/.
e.g.:
哪里是你的registrations_controller。rb保存?位置是很重要的。我发现把它保存到app/控制器/设计/设计中是错误的。它只需要保存在app/controller /中。例如:
app/controllers/registrations_controller.rb
app / controllers / registrations_controller.rb
Also, config/routes.rb
route should be defined as:
同时,配置/路线。rb路径定义为:
devise_for :users, controllers: { registrations: 'registrations' }
devise_for:用户,控制器:{注册:'注册'}
#2
2
I got same problem with some classes in lib (used config.autoload_paths += Dir["#{config.root}/lib/**/"]
)
我在lib中遇到了同样的问题(使用配置)。autoload_paths + = Dir(" # { config.root } / lib / * * / "))
for me helped to switch rails from 4.0.0.rc1
to 4.0.0
对我来说,帮助我从4.0.0转换rails。rc1,4.0.0
#3
2
Well, I got relief after adding the following line in my development.rb
嗯,在我的发展中加入了以下几条线后,我得到了解脱。
config.middleware.delete Rack::Lock
Reference: https://github.com/websocket-rails/websocket-rails/issues/101
参考:https://github.com/websocket-rails/websocket-rails/issues/101
You can try this once at last.
你终于可以试一次了。
#4
2
I had a similar problem.
我也有类似的问题。
And then realised I have the same file duplicated in different folders inside controller, and that was causing the problem.
然后我意识到我有相同的文件在控制器的不同文件夹中复制,这导致了问题。
I had both files with the same content:
我有两个文件都有相同的内容:
app/controllers/logs_controller.rb
app/controllers/api/logs_controller.rb
#5
0
a lot of gems started breaking on rails 4 , all due to the problem of unloadable in controllers. https://github.com/flyerhzm/switch_user/issues/34 https://github.com/thoughtbot/high_voltage/issues/68 https://github.com/thoughtbot/clearance/issues/276 and many more
很多gem开始在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等等
you should look into errors that which gem is creating the problem. Once you know that: 1) Check the open issues of that gem 2) If that issue exists and fixed , make sure you have that fix or else update the gem. 3)If not you can create an issue and ask them to fix it. 4) If you dont want to wait for their fix , you can form the gem and push a fix for it https://github.com/cashins/email_preview/commit/b34a077a954b98bd086153fae8979ad142667555 all fix are the same(removing unloadable from the specified controller )
您应该查看gem正在创建问题的错误。一旦您知道:1)检查gem的开放问题2)如果该问题存在并得到了修复,请确保您已经进行了修复或者更新了gem。如果没有,你可以创建一个问题,并要求他们解决它。4)如果您不想等待他们的修复,您可以组成gem并为它推送一个修复:https://github.com/cashins/email_preview/commit/b34a077a954b98bd086153fae89ad142667555所有的修复都是相同的(从指定的控制器中删除不可加载的)
Hope it helps.
希望它可以帮助。
if nothing helps downgrade your rails version.
如果没有什么可以帮助降级您的rails版本。
#6
0
I found this works in development.rb:
我发现这个正在开发中。
config.reload_classes_only_on_change = false
(I previously tried deleting Gemfile.lock and running bundle update, as well as changing Rails version, as mentioned here and elsewhere. They didn't work for me.)
(我之前尝试过删除Gemfile。锁和运行bundle更新,以及更改Rails版本,这里和其他地方都提到过。他们不是为我工作的。
#7
0
I created the same error with a typo, I had
我犯了同样的错误
module EmployeeReminderssHelper
when the helper file was called
调用助手文件时
employee_reminders_helper.rb
(Note the extra 's')
(注意额外的“s”)
#8
-1
The devise wiki had this to say on the topic:
设计维基在这个话题上说:
裁判:https://github.com/plataformatec/devise/wiki/How-To:-redirect-to-a-specific-page-on-successful-sign-in # preventing-redirect-loops
Preventing redirect loops
Because the code for after_sign_in_path_for above only checks if request.referer == sign_in_url, these methods (which call after_sign_in_path_for) will also have to be overridden (else you will encounter redirect loops):
因为上面的after_sign_in_path_for代码只检查请求。referer == = sign_in_url,这些方法(调用after_sign_in_path_for)也必须被重写(否则会遇到重定向循环):
Devise::PasswordsController#after_resetting_password_path_for
Devise::RegistrationsController#after_sign_up_path_for
Devise::RegistrationsController#after_update_path_for
This can be done like so:
可以这样做:
# routes.rb
devise_for :users, controllers: { registrations: 'users/registrations', passwords: 'users/passwords' }
# users/registrations_controller.rb
class Users::RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
signed_in_root_path(resource)
end
def after_update_path_for(resource)
signed_in_root_path(resource)
end
end
# users/passwords_controller.rb
class Users::PasswordsController < Devise::PasswordsController
protected
def after_resetting_password_path_for(resource)
signed_in_root_path(resource)
end
end
#1
11
Where was your registrations_controller.rb
saved to? The location is important. I found that I was making a mistake saving it to app/controllers/devise/.
. It simply needed to be saved in app/controllers/.
e.g.:
哪里是你的registrations_controller。rb保存?位置是很重要的。我发现把它保存到app/控制器/设计/设计中是错误的。它只需要保存在app/controller /中。例如:
app/controllers/registrations_controller.rb
app / controllers / registrations_controller.rb
Also, config/routes.rb
route should be defined as:
同时,配置/路线。rb路径定义为:
devise_for :users, controllers: { registrations: 'registrations' }
devise_for:用户,控制器:{注册:'注册'}
#2
2
I got same problem with some classes in lib (used config.autoload_paths += Dir["#{config.root}/lib/**/"]
)
我在lib中遇到了同样的问题(使用配置)。autoload_paths + = Dir(" # { config.root } / lib / * * / "))
for me helped to switch rails from 4.0.0.rc1
to 4.0.0
对我来说,帮助我从4.0.0转换rails。rc1,4.0.0
#3
2
Well, I got relief after adding the following line in my development.rb
嗯,在我的发展中加入了以下几条线后,我得到了解脱。
config.middleware.delete Rack::Lock
Reference: https://github.com/websocket-rails/websocket-rails/issues/101
参考:https://github.com/websocket-rails/websocket-rails/issues/101
You can try this once at last.
你终于可以试一次了。
#4
2
I had a similar problem.
我也有类似的问题。
And then realised I have the same file duplicated in different folders inside controller, and that was causing the problem.
然后我意识到我有相同的文件在控制器的不同文件夹中复制,这导致了问题。
I had both files with the same content:
我有两个文件都有相同的内容:
app/controllers/logs_controller.rb
app/controllers/api/logs_controller.rb
#5
0
a lot of gems started breaking on rails 4 , all due to the problem of unloadable in controllers. https://github.com/flyerhzm/switch_user/issues/34 https://github.com/thoughtbot/high_voltage/issues/68 https://github.com/thoughtbot/clearance/issues/276 and many more
很多gem开始在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等等
you should look into errors that which gem is creating the problem. Once you know that: 1) Check the open issues of that gem 2) If that issue exists and fixed , make sure you have that fix or else update the gem. 3)If not you can create an issue and ask them to fix it. 4) If you dont want to wait for their fix , you can form the gem and push a fix for it https://github.com/cashins/email_preview/commit/b34a077a954b98bd086153fae8979ad142667555 all fix are the same(removing unloadable from the specified controller )
您应该查看gem正在创建问题的错误。一旦您知道:1)检查gem的开放问题2)如果该问题存在并得到了修复,请确保您已经进行了修复或者更新了gem。如果没有,你可以创建一个问题,并要求他们解决它。4)如果您不想等待他们的修复,您可以组成gem并为它推送一个修复:https://github.com/cashins/email_preview/commit/b34a077a954b98bd086153fae89ad142667555所有的修复都是相同的(从指定的控制器中删除不可加载的)
Hope it helps.
希望它可以帮助。
if nothing helps downgrade your rails version.
如果没有什么可以帮助降级您的rails版本。
#6
0
I found this works in development.rb:
我发现这个正在开发中。
config.reload_classes_only_on_change = false
(I previously tried deleting Gemfile.lock and running bundle update, as well as changing Rails version, as mentioned here and elsewhere. They didn't work for me.)
(我之前尝试过删除Gemfile。锁和运行bundle更新,以及更改Rails版本,这里和其他地方都提到过。他们不是为我工作的。
#7
0
I created the same error with a typo, I had
我犯了同样的错误
module EmployeeReminderssHelper
when the helper file was called
调用助手文件时
employee_reminders_helper.rb
(Note the extra 's')
(注意额外的“s”)
#8
-1
The devise wiki had this to say on the topic:
设计维基在这个话题上说:
裁判:https://github.com/plataformatec/devise/wiki/How-To:-redirect-to-a-specific-page-on-successful-sign-in # preventing-redirect-loops
Preventing redirect loops
Because the code for after_sign_in_path_for above only checks if request.referer == sign_in_url, these methods (which call after_sign_in_path_for) will also have to be overridden (else you will encounter redirect loops):
因为上面的after_sign_in_path_for代码只检查请求。referer == = sign_in_url,这些方法(调用after_sign_in_path_for)也必须被重写(否则会遇到重定向循环):
Devise::PasswordsController#after_resetting_password_path_for
Devise::RegistrationsController#after_sign_up_path_for
Devise::RegistrationsController#after_update_path_for
This can be done like so:
可以这样做:
# routes.rb
devise_for :users, controllers: { registrations: 'users/registrations', passwords: 'users/passwords' }
# users/registrations_controller.rb
class Users::RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
signed_in_root_path(resource)
end
def after_update_path_for(resource)
signed_in_root_path(resource)
end
end
# users/passwords_controller.rb
class Users::PasswordsController < Devise::PasswordsController
protected
def after_resetting_password_path_for(resource)
signed_in_root_path(resource)
end
end