Ruby on Rails: required parameters for model
<p>Rails 5. I have model User and I want field "login" to be obligatory.</p>

<p>What I did:</p>

<pre><code>class User &lt; ApplicationRecord
  has_one :cart

  def create
    User.create(user_params)
  end

  private
  def user_params
    params.require(:user).permit(:login)
  end
end
</code></pre>

<p>But it doesn't work. I can save new user without login.</p>

<pre><code>irb(main):001:0&gt; user2 = User.create

begin transaction

SQL (1.5ms)  INSERT INTO "users" ("created_at", "updated_at") VALUES (?, ?)  [["created_at", 2016-08-21 11:38:17 UTC], ["updated_at", 2016-08-21 11:38:17 UTC]]

commit transaction

=&gt; #&lt;User id: 4, login: nil, created_at: "2016-08-21 11:38:17", updated_at: "2016-08-21 11:38:17"&gt;
</code></pre>

<p>How to fix it?</p>