Saving custom fields in devise User model in Rails 4.1.4 -
I just follow the guide to add column 'first name' and 'second name' to command in the user's user model I am / P>
Rail Migration add_firstname_to_user generates the first name: String Rail Migration add_secondname_to_user generates another name: string
and I tell the changes with: / P>
rake db: migrate
This works right, because I can see those fields through the console with the user. However, the problem I am right now is that I do not see the attr_accessible field in App / Modal / UserRbb.
So I've added the following lines now:
gt; & Lt;% = f.label: first_name% & gt; & Lt; Br / & gt; & Lt;% = f.text_field: First Name, Autofocus: True% & gt; & Lt; / Div & gt; & Lt; Div & gt; & Lt;% = f.label: second_name% & gt; & Lt; Br / & gt; & Lt;% = f.text_field: second name, autofocus: true%> & Lt; / Div & gt; In the app / view / devise / registrations in new.html.erb, but this is not working, because I have found that the first name on the name of my registered user and the other Name attributes are zero I
What can I do? I think there is something about attr_accessible step, but I could not find it.
Any help would be appreciated.
For custom fields 'first name' and 'second name', you can enter the following code in your application controller: You can make them accessible by adding
class ApplicationController & lt; ActionController :: Before use_filters: configure_permitted_parameters, if: devise_controller? Protect def define_permitted_parameters devise_parameter_sanitizer.for (: sign_in) {| U | U.permit (: username,: email, first name, second name)} devise_parameter_sanitizer.for (: sign_up) {| U | U.permit (: Username, Email: Password: Password_confirmation, firstname, secondname)} devise_parameter_sanitizer.for (: account_update) {| U |
You can add more custom fields and allow them here, change the code according to your needs.
Comments
Post a Comment