ruby - Rails 4: Devise not populating users table with correct information -
i have small rails 4 app has devise , simple form installed.
my controller this:
class usercontroller < applicationcontroller def create user.create(user_params) end private def user_params params.require(:user).permit(:first_name, :last_name, :profile_name, :email, :password, :password_confirmation]) end end
my form sign follows:
<h2>sign up</h2> <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) |f| %> <%= devise_error_messages! %> <div class="field"> <%= f.label :first_name %><br /> <%= f.text_field :first_name, autofocus: true %> </div> <div class="field"> <%= f.label :last_name %><br /> <%= f.text_field :last_name, autofocus: true %> </div> <div class="field"> <%= f.label :profile_name %><br /> <%= f.text_field :profile_name, autofocus: true %> </div> <div class="field"> <%= f.label :email %><br /> <%= f.email_field :email, autofocus: true %> </div> <div class="field"> <%= f.label :password %> <% if @validatable %> <em>(<%= @minimum_password_length %> characters minimum)</em> <% end %><br /> <%= f.password_field :password, autocomplete: "off" %> </div> <div class="field"> <%= f.label :password_confirmation %><br /> <%= f.password_field :password_confirmation, autocomplete: "off" %> </div> <div class="actions"> <%= f.submit "sign up" %> </div> <% end %>
however, when @ data in table, it's displaying email , password fields. first , last name, profile name aren't being stored against record.
is there i've missed here that's preventing of fields being saved on creating new user? trying work out i've missed here!
try changing applicationcontroller
(the fastest way) according documentation:
class applicationcontroller < actioncontroller::base before_action :configure_permitted_parameters, if: :devise_controller? protected def configure_permitted_parameters devise_parameter_sanitizer.for(:sign_up) << :first_name << :last_name << :profile_name end end
check according part of documentation.
hope helps!
ps. 1.
if want customise controller, should:
generate 1 (yours looks you've created on own).
rails generate devise:controllers [scope]
customise generated controller:
class users::sessionscontroller < devise::sessionscontroller # customisations here # # /resource/sign_in # def new # super # end ... end
check this part of documentation.
ps. 2.
in code have line like:
params.require(:user).permit(:first_name, :last_name, :profile_name, :email, :password, :password_confirmation])
it should cause syntax error (i'm surprised if doesn't). should remove ]
in end of list:
params.require(:user).permit(:first_name, :last_name, :profile_name, :email, :password, :password_confirmation])
Comments
Post a Comment