Adding nested attributes to devise user model

后端 未结 2 1746
醉话见心
醉话见心 2021-01-23 11:12

At first glance it would seem this question has been answered before, but not on my case (most are related to mass assignment issues and/or mongoid.) I have not been able to fin

相关标签:
2条回答
  • 2021-01-23 11:42

    I was able to solve this in my application, but I am using strong parameters. However the solution should still be applicable in your case.

    Instead of overriding all of the methods in the RegistrationsController I just overrode build_resource to pass in the correct parameters needed.

    def build_resource(params)
      super(resource_params)
    end
    
    def resource_params
      params.require(:user).permit(:email, :password, tickets_attributes: [ :description ] )
    end
    

    I also have the inverse_of on my User and Ticket models, Like this:

    user.rb
      has_many :tickets, inverse_of: :user
    
    ticket.rb
      belongs_to :user, inverse_of :tickets
    
    0 讨论(0)
  • 2021-01-23 11:46

    Forgot to add user_id to address migration. Rails expected it when adding belongs_to :user to the address model.

    0 讨论(0)
提交回复
热议问题