我目前使用两种模式,teachers
和users
。Rails:autopopulate表格字段
我允许小组老师注册(使用设计)他们自己的用户,他们将通过teacher_id与这些教师关联。例如,教师Id为1的小组成员将全部参与领导者1的队列。
更新:我原来的问题是如何添加隐藏字段。我已经添加了一个隐藏字段,但由于某些奇怪的原因数据正在保存到Db。新用户有一个空白的教师ID。任何帮助,将不胜感激。
注册记忆控制器
class RegistrationsController < Devise::RegistrationsController
private
def sign_up_params
params.require(:user).permit(:teacher, :teacher_id, :user_id, :username, :first_name, :last_name, :email, :password, :password_confirmation)
end
def account_update_params
params.require(:user).permit(:teacher, :teacher_id, :user_id, :username, :first_name, :last_name, :email, :password, :password_confirmation, :current_password)
end
end
enter code here
New.html.erb
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<div>
<% if teacher_signed_in? %>
<p>
Sign up new student. Enter in the name, email and password that your student will use to sign in.
<%= hidden_field_tag :teacher_id, current_teacher.id %>
<% else %>
<% end %>
<%= f.input :username, required: true, autofocus: true %>
<%= f.input :email, required: true %>
<%= f.input :password, required: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length) %>
<%= f.input :password_confirmation, required: false %>
</div>
<div class="form-actions">
<%= f.button :submit, "Sign up" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
enter code here
这个工作据我所知。我刚刚编辑了注册控制器,添加了.merge(teacher_id:current_teacher.id) –