0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

deviseのcontroller#createをいじったけどエラーでた時のメモ

Posted at
app/contoller/customers/registrations_controller.rb
class Customers::RegistrationsController < Devise::RegistrationsController
  before_action :configure_sign_up_params, only: [:create]

...
  def create
    super
    @customer.company_id = params[:company_id]
    binding.pry
    if @customer.save
      CustomerStatus.create(paid: false, room_plus: false, dozen_sessions: false, numbers_of_contractnt: 0, customer_id: @customer.id)
    end
  end
...
  protected

  def configure_sign_up_params
    devise_parameter_sanitizer.permit(:sign_up, keys: [:company_id])
  end

カスタマーをずっと保存できなかった。
スクリーンショット 2020-12-12 15.14.49.png

原因はモデルのcustomer.rbのここでした
スクリーンショット 2020-12-12 15.16.21.png

deviseはbelongs_to をしたら新規登録でうまくいかなくなるみたいなので、気をつけましょうというメモです。

## 解決法
####7行目の部分です
スクリーンショット 2020-12-12 15.17.46.png

以上!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?