I am trying to sign up using devise for an application I am making. The form submit action is sending the correct params but I am failing on one presence validation. That presence validation is a checkbox field where a user selects on sign up whether they are single or not.
Here is the code for views/devise/registrations/new.html.erb
<div class="radio">
<%= f.label :relationship_status%><br />
<%= radio_button_tag(:relationship_status, "single") %>
<%= label_tag(:single, "Single") %>
<%= radio_button_tag(:relationship_status, "relationship") %>
<%= label_tag(:relationship, "In a relationship") %>
</div>
Here is the ApplicationController where I specify the params to be passed aside from the defaults provided by devise:
class ApplicationController < ActionController::Base
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:name,
:username, :birthday,
:relationship_status])
end
end
Here is my user model where I set basic presence validators
class User < ApplicationRecord
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
validates :name, :email, :username,
:birthday,:relationship_status, presence: true
end
Finally, here is an image of clicking Sign Up once I fill the form:
ActiveRecord::Schema.define(version: 2019_06_05_024141) do
create_table "users", force: :cascade do |t|
t.string "name", null: false
t.string "username", null: false
t.datetime "birthday", null: false
t.string "relationship_status", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
end
As you can see in the picture relationship_status
is clearly set to single. Yet I keep getting an error saying that it can't be blank. I am stumped and some help would be appreciated. Thank you.
relationship_status
is cause of rollback? have you tried with the debugger? So far i can see yourbirthday
is making issue. – Anand