Question

I'm relatively new to rails and am using devise for my user sign up and sign in processes. At sign up if a user doesn't have an invite token I would like them to also sign up and create their business that will be associated with their user account.

Below is a screenshot of the error I am getting in my RegistrationsController when trying to create the new business.

NoMethodError in RegistrationsController

Here is my code in the registrations_controller.rb:

if params[:invite_code]
    ...
else
    resource = build_resource({})
    resource.businesses.build()  # Inserts a blank object for business
    respond_with resource
end

Any ideas on why it isn't able to pass the business information provided and create a new business? Thanks in advance for any help.

Was it helpful?

Solution

I think it's just a pluralization issue. The has_one association on the User should be singular (:business) as should the method call in the controller (resource.business.build()) and accepts_nested_attributes_for.

That being said, that part of the controller should never even be getting hit. All of your logic should be contained within this first conditional. Everything happening here should probably be pulled out into another method and called after the successful save. Here's a new gist with a refactoring of registrations_controller.rb: https://gist.github.com/ccschmitz/7ea0a41180e25de9168d

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top