ruby on rails - Devise Custom Controller not creating record in nested form -


this working, i've made change somewhere , cannot work. have nested form create company along first contact uses devise. company record being created contact (devise model) isn't being created. if create company , add contact company, contact created i'm pretty sure controller works. need set of eyes spot mistake.

error: runtimeerror in companiescontroller#create not find valid mapping nil

companiescontroller (relevant methods):

  class companiescontroller < applicationcontroller   before_action :set_company, only: [:show, :edit, :update, :destroy]   before_action :authenticate_contact!, only: [:index, :show, :edit, :update, :destroy]       # /companies/new   def new    @company = company.new    @company.contacts.build   end     # post /companies   # post /companies.json   def create     @company = company.new(company_params)     respond_to |format|       if @company.save         sign_in(@company.contacts.first)         format.html { redirect_to @company, notice: 'company created.' }         format.json { render action: 'show', status: :created, location: @company }       else         format.html { render action: 'new' }         format.json { render json: @company.errors, status: :unprocessable_entity }       end     end   end      # never trust parameters scary internet, allow white list through.     def company_params       params.require(:company).permit(:name, :legal_entity, :kvk_number, :vat_number, :kvkdoc, contacts_attributes:[:first_name, :last_name, :address, :phone, :email, :postcode, :password] )     end   end 

contacts registration controller:

class contacts::registrationscontroller < devise::registrationscontroller # custom controller inherits standard devise registration controller.  # controller used user added existing account not it's own account.  # skips standard devise authentication filter allow active user session create user recorod. skip_before_filter :require_no_authentication  # custom method ensure user on page has active session ensure account accessable. before_filter :has_current_contact   # create method call standard devise create method def create   super end  protected  # stop user sessisons being switched new user def sign_up(resource_name, resource)   true end  # test see person on page has active session def has_current_contact   if current_contact.nil?     redirect_to root_path, alert: 'you need logged in this!'    end end  # sets permited params registration. inherits standard devise parameters defined in  # application controller , merges account id of current user. def sign_up_params   devise_parameter_sanitizer.sanitize(:sign_up).merge(company_id: current_contact.company_id) end 

end

i can see code throws error on attempt find contact company , sign in since can't find contact given none has been created, can't figure out why it's not being created.

help?


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -