我有两个表,公司和员工,所以我想在我注册一个员工的时候,他的注册也是针对已经登录的公司,也就是说,不必选择那个员工的哪个公司。我将如何在 ruby on rails 中做到这一点?我正在使用 gem devise 登录。
在您的用户控制器中试试这个:
@user = User.new(user_params)
@user.company_id = current_company.id
respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: 'User was successfully created.' }
format.json { render :show, status: :created, location: @user }
else
format.html { render :new }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句