Rails Devise - Register User with Associated Model

前端 未结 1 804
失恋的感觉
失恋的感觉 2021-01-23 01:52

I\'ve come across a few SO questions on this topic, but all seem out of date or simply bad coding practice.

Problem: I am signing up a user as part of a checkout flow. I

相关标签:
1条回答
  • 2021-01-23 02:13

    In your application_controller.rb

    class ApplicationController < ActionController::Base
    before_action :configure_strong_params, if: :devise_controller?
    
      def configure_strong_params
      devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:username, :name, 
        :addresses_attributes => [:address, :address2, :city, :state_id, :zip_code]) }
      end
    end
    

    Now in your registration form you can use address_attributes & devise signup params will accept this.

    Now to rescue from the filter chain halted, please try this in your registrations_controller.rb file

    class RegistrationsController < Devise::RegistrationsController
     skip_before_filter :require_no_authentication, only: :create
     #other codes 
    end
    
    0 讨论(0)
提交回复
热议问题