我目前使用兩種模式,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) –