为#

设计注册我得到了这个错误:

undefined method `users_url' for # 

有了Omniauth facebook,登录,一切正常。

 class User  :destroy after_save :myprofile def myprofile if self.profile else Profile.create(user_id: self.id, user_name: self.name) end end end class Profile < ActiveRecord::Base belongs_to :user end 

使用设计注册可以解决这个问题的解决方案是什么?

重要提示:它适用于omniauth facebook ,但它不适用于设计注册。

编辑:我在Profile.create中遇到此错误! 方法:

 NoMethodError - undefined method `users_url' for #: actionpack (3.2.13) lib/action_dispatch/routing/polymorphic_routes.rb:129:in `polymorphic_url' actionpack (3.2.13) lib/action_dispatch/routing/url_for.rb:150:in `url_for' actionpack (3.2.13) lib/action_controller/metal/redirecting.rb:105:in `_compute_redirect_to_location' actionpack (3.2.13) lib/action_controller/metal/redirecting.rb:74:in `redirect_to' actionpack (3.2.13) lib/action_controller/metal/flash.rb:25:in `redirect_to' 

Edit_2: Github repo: https //github.com/gwuix2/anabol

Github问题:

https://github.com/plataformatec/devise/issues/2457

问题解决了:

在profile.rb中:

 validates_uniqueness_of :slug 

导致问题,因为对于Profile.user_name,user.rb中有以下内容:

 after_save :myprofile def myprofile Profile.create!(user_id: self.id, user_name: self.name) end 

通过向User.name添加唯一性validation解决了问题,然后将其作为唯一传递给配置文件,然后创建唯一的:slug。

user.rb:

 validates_uniqueness_of :name 

您使用Profile.create(user_id: self.id, user_name: self.name)创建的配置文件不与任何用户关联。 为了构建has_one依赖项,在after_create回调中使用self上的after_create方法:

 # app/models/user.rb class User < ActiveRecord::Base has_one :profile, :dependent => :destroy after_create :myprofile def myprofile profile = Profile.create!(user_id: self.id, user_name: self.name) # `.create!` will throw an error if this fails, so it's good for debugging self.profile = profile end end