ruby on rails - Data not getting saved to database from the form -
class usercontroller has following code:
def create @user = user.new(params[:user].permit(:userid,:password,:email)) render plain: params[:user].inspect+"||"+@user.inspect #@user.save #flash[:notice] = "you signed successfully" #redirect_to @user end
the form has following code: (@user
or :user
, doesn't matter, output same)
<%= form_for :user, url:users_path |f| %> <%= f.label:userid %><%= f.text_field :userid %><br /> <%= f.label:password %><%= f.password_field :password %><br /> <%= f.label:email %><%= f.text_field :email %><br /> <br /> <%= f.submit %> <% end %>
when fill form, output:
{"userid"=>"viky", "password"=>"123456", "email"=>"aa"}||#<user id: nil, userid: nil, password: nil, email: nil, created_at: nil, updated_at: nil>
as can see, userid , password , email getting passed in params not appearing in @users, don't know why. , if type @users.save saves null row in database.
i guess permit syntax wrong
use : params.require(:user).permit(:userid,:password,:email)
Comments
Post a Comment