質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Q&A

0回答

1024閲覧

SignUpの際のエラーに関する件

退会済みユーザー

退会済みユーザー

総合スコア0

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

0グッド

0クリップ

投稿2018/06/16 07:22

現在、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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2018/06/20 15:24

どんなエラーなのかすらわからないので回答しかねます。byebug差し込んで調べてみましたか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問