Develop an undefined method `users_url 'for # <Devise :: RegistrationsController: 0x00000003b299b0>

I get this error when registering a development:

undefined method `users_url' for #<Devise::RegistrationsController:0x00000003b299b0>

With Omniauth facebook, login, everything works fine.

class User < ActiveRecord::Base
  has_one :profile, :dependent => :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

What could be the solution for this work with registration?

Important: it works with omniauth facebook , but it does not work with development .

Edit: I get this error using Profile.create! Method:

NoMethodError - undefined method `users_url' for #<Devise::RegistrationsController:0x00000005946e20>:
  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 problem:

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

0
source share
2 answers

Problem resolved:

in 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, , : slug.

user.rb:

validates_uniqueness_of :name
+1

, Profile.create(user_id: self.id, user_name: self.name), . has_one, build_resource 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 good for debugging
        self.profile = profile
    end
end
0

All Articles