我的admin / views / parents / new.html.erb文件:
<%= form_for ([:admin, @parent]) do |f| %>
<% if @parent.errors.any? %>
<div id="error_explanation">
<ul>
<% @parent.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.label :username %> <br />
<%= f.text_field :username %> <br/>
<%= f.password_field :password %> <br />
<%= f.password_field :password_confirmation %><br />
<%= f.submit %>
<% end %>
model models / parent.rb
class Parent < ActiveRecord::Base
has_secure_password
belongs_to :student
end
控制器:admin / controllers / parents_controller.erb
def new
@parent = Parent.new
end
def show
end
def create
@parent = Parent.create(params[:create])
if @parent.save
redirect_to "admin"
else
render :action => 'new'
end
end
当我按提交时,我收到错误,password digest can't be blank
但密码字段已填写
答案 0 :(得分:0)
PARAMS [:创建] 我认为它应该是params [:parent]