我一直在尝试注册用户并将他的个人资料数据保存在另一个桌子上,因为我有不同类型的用户。当他们注册时,他们被要求根据他们的不同领域(客户,业务等),我不能让它工作。 这是我的模特
<script>
$(document).ready(function(){
var expiration = new Date(Date.UTC(2018, 8, 1)).toUTCString();
var cookie = escape(popup) + "=" + escape(modal.style.display) + ";expires=" + expiration + ";";
document.cookie = cookie;
// read cookie
var state = modal.style.display
var key = modal.style.display + "=";
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];
while (cookie.charAt(0) === ' ') {
cookie = cookie.substring(1, cookie.length);
}
if (cookie.indexOf(key) === "block") {
modal.style.display = "block";
}
else if (cookie.indexOf(key) === "none") {
modal.style.display = "none";
}
}
});
</script>
和客户模式
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_one :cliente, dependent: :destroy
before_create :build_cliente
accepts_nested_attributes_for :cliente
end
我的应用程序控制器
class Cliente < ApplicationRecord
belongs_to :user
end
表格:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :authenticate_user!
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [address_attributes: [:nombre, :apellidos]])
end
end
我不知道为什么但是它在表clientes上创建了一个注册表,但它只有默认id和正确引用的user_id。我是铁杆和编码的新手。我有点失落。任何帮助,将不胜感激。另外,我知道我的英语有点生疏,希望你理解这篇文章。
答案 0 :(得分:0)
看起来大部分是正确的,但你的强参数可能应该是cliente_attributes。见https://community.rstudio.com/t/dramatic-screen-resolution-issue-see-screen-snip/3703/6