現在、RubyonrailsでSign Upを作成しようとしております。
deviceユーザー機能に
・company
・employment
の二つのmodelを共にsign upのnewで登録出来る仕様を作成しているのですが、controllerのエラーで上手く行かずにつまづいています。
エラー点は以下のようです。
以下太字にて記載しておりますが、
** @employment.company = @company
**
この部分にエラーが出ています。
ご教示いただければと存じます。
よろしくお願い致します。
registrations_controller.rb
1# frozen_string_literal: true 2 3class Users::RegistrationsController < Devise::RegistrationsController 4 # before_action :configure_sign_up_params, only: [:create] 5 # before_action :configure_account_update_params, only: [:update] 6 layout "top", only: [:new] 7 # GET /resource/sign_up 8 def new 9 super 10 @company = Company.new 11 @employment = Employment.new 12 end 13 14 # POST /resource 15 def create 16 @company = Company.new(company_params) 17 @employment = Employment.new(employment_params) 18 if @company.valid? 19 if @employment.valid? 20 super do |resource| 21 if resource.errors.present? 22 render :new and return 23 end 24 @company.save 25** @employment.company = @company** 26 @employment.save 27 resource.update(company: @company) 28 end 29 end 30 end 31 end 32 33 34 # GET /resource/edit 35 # def edit 36 # super 37 # end 38 39 # PUT /resource 40 # def update 41 # super 42 # end 43 44 # DELETE /resource 45 # def destroy 46 # super 47 # end 48 49 # GET /resource/cancel 50 # Forces the session data which is usually expired after sign 51 # in to be expired now. This is useful if the user wants to 52 # cancel oauth signing in/up in the middle of the process, 53 # removing all OAuth session data. 54 # def cancel 55 # super 56 # end 57 58 # protected 59 60 # If you have extra params to permit, append them to the sanitizer. 61 # def configure_sign_up_params 62 # devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute]) 63 # end 64 65 # If you have extra params to permit, append them to the sanitizer. 66 # def configure_account_update_params 67 # devise_parameter_sanitizer.permit(:account_update, keys: [:attribute]) 68 # end 69 70 # The path used after sign up. 71 # def after_sign_up_path_for(resource) 72 # super(resource) 73 # end 74 75 # The path used after sign up for inactive accounts. 76 # def after_inactive_sign_up_path_for(resource) 77 # super(resource) 78 # end 79 80 81 private 82 def company_params 83 params.require(:company).permit( 84 :company 85 ) 86 end 87 88 89 private 90 def employment_params 91 params.require(:employment).permit( 92 :trial_period 93 ) 94 end 95 96end 97
どんなエラーなのかすらわからないので回答しかねます。byebug差し込んで調べてみましたか?
あなたの回答
tips
プレビュー