Reputation: 27
I'm working with a form that belongs to the signup and account update pages with Devise. I've added 2 fields to the user model, Role and Gender.
I've setup my role field as:
<%= f.select :role, options_for_select([['Student - High School'], ['Student - Undergraduate'], ['Student - Nursing'], ['Student - Graduate'], ['Student - Medical'], ['Health Care - Resident'], ['Health Care - Nurse'], ['Health Care - Physician'], ['Health Care - Staff'], ['Other']]), class: 'form-control' %>
and gender as:
<%= f.select :gender, options_for_select([['Male'], ['Female'], ['Other']]), class: 'form-control' %>
And in my application controller, I've asked Devise to permit:
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [ :email, :password, :password_confirmation, :age, :name, role: [], gender:[]])
devise_parameter_sanitizer.permit(:account_update, keys: [ :email, :password, :password_confirmation, :age, :name, role: [], gender: []])
end
Can you help me find the mistake I'm making? Thank You!
Upvotes: 0
Views: 89
Reputation: 833
Try this in the views:
options_for_select(['Student - High School', 'Student - Undergraduate', 'Student - Nursing', 'Student - Graduate', 'Student - Medical', 'Health Care - Resident', 'Health Care - Nurse', 'Health Care - Physician', 'Health Care - Staff', 'Other'], selected: 'Student - High School')
options_for_select(['Male', 'Female', 'Other'], selected: 'Male')
And this in the controller:
devise_parameter_sanitizer.permit(:sign_up, keys: [ :email, :password, :password_confirmation, :age, :name, :role, :gender ])
devise_parameter_sanitizer.permit(:account_update, keys: [ :email, :password, :password_confirmation, :age, :name, :role, :gender ])
Upvotes: 0
Reputation: 1505
You should put your devise controllers into your app.
rails generate devise:controllers [scope]
Then put that permitted params method in the registrations controller
class Users::RegistrationsController < Devise::RegistrationsController
before_action : configure_permitted_parameters
private
#Your methods here
end
routes:
devise_for :users, :controllers => {:registrations => "registrations"}
Upvotes: 1