我正在使用設計,並且我想將字段名字和姓氏添加到sign_up表單。 創建相應的列之後,我嘗試使用新表單進行sign_up,但數據庫中新字段的值爲零。使用設計的自定義用戶字段
之後,我創造了這個控制器:
class RegistrationsController < Devise::RegistrationsController
private
def sign_up_params
params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation)
end
def account_update_params
params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :current_password)
end
end
但是我還是在列如first_name和last_name爲零。 我錯過了什麼嗎?
形式:
<h2>Sign up</h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :first_name %><br />
<%= f.text_field :first_name %></div>
<div><%= f.label :last_name %><br />
<%= f.text_field :last_name %></div>
<div><%= f.label :profile_name %><br />
<%= f.text_field :profile_name %></div>
<div><%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %></div>
<div><%= f.label :password %> <% if @validatable %><i>(<%= @minimum_password_length %> characters minimum)</i><% end %><br />
<%= f.password_field :password, autocomplete: "off" %></div>
<div><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %></div>
<div><%= f.submit "Sign up" %></div>
<% end %>
<%= render "devise/shared/links" %>
結帳這個海峽跟隨文章http://www.jacopretorius.net/2014/03/adding-custom-fields-to-your-devise-user-model- in-rails-4.html – 2014-09-11 13:23:31
http://stackoverflow.com/questions/16297797/add-custom-field-column-to-devise-with-rails-4 – yozzz 2014-09-11 13:23:57