消息表示您尚未为您的新用户记录设置username
字段。有一种方法可以解决它。在您的app/views/users/new.html.erb
文件中,您需要添加一个username
字段。因此,它看起来像下面这样:
<h1>Sign Up</h1>
<%= form_for @user do |f| %>
<% if @user.errors.any? %>
<div class="error_messages">
<h2>Form is invalid</h2>
<ul>
<% for message in @user.errors.full_messages %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :username %>
<%= f.text_field :username %>
</div>
<div class="field">
<%= f.label :email %>
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :password %>
<%= f.password_field :password %>
</div>
<div class="field">
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation %>
</div>
<div class="actions"><%= f.submit %></div>
<% end %>
此外,您还需要修复参数过滤你的app/controllers/users_controller.rb
。此更新您的user_params
方法:
def user_params
params.require(:user).permit(:username, :email, :password, :password_confirmation, :remember_me)
end
这就是它!它应该现在工作。
发布您的应用程序的相关代码 –
欢迎来到Stack Overflow。为了最好地解决您的问题,您需要发布一个“好问题”。请检查这里的指导:http://stackoverflow.com/help/on-topic。通过在生成此SQL的代码周围发布代码,可以改进您的问题。您还可能想要检查:为什么您要在不包含用户名的情况下将用户的值插入到用户表中? – GreenAsJade