参数缺失或值为空:用户 rails 4 [英] param is missing or the value is empty: user rails 4

查看:54
本文介绍了参数缺失或值为空:用户 rails 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试提交注册表时,出现以下错误.参数缺失或值为空:用户

I am getting the following error, when i try to submit my registration form. param is missing or the value is empty: user

def user_params
   params.require(:user).permit(:name, :email, :password, :password_confirmation)
end

请求如下:

{"utf8"=>"✓",
 "authenticity_token"=>"YX0+4AeWlGWJiQZgbhV9cxi6TUCoibZfwh95BrK9iCQ=",
 "name"=>"asasa",
 "email"=>"asasas@asas.com",
 "password"=>"[FILTERED]",
 "confirm_password"=>"[FILTERED]",
 "commit"=>"Register"}

以下是我的观点

<%= form_tag users_path, class: "form-horizontal", id: "signupform" do %>

<%= end %>

推荐答案

那里没有 params[:user] ,这就是错误告诉你的.您是否希望您的参数看起来像这样?

there is no params[:user] there, that's what the error is telling you. Are you perhaps expecting your params to look like this?

{"utf8"=>"✓",
 "authenticity_token"=>"YX0+4AeWlGWJiQZgbhV9cxi6TUCoibZfwh95BrK9iCQ=",
 "user" => {"name"=>"asasa",
            "email"=>"asasas@asas.com",
            "password"=>"[FILTERED]",
            "confirm_password"=>"[FILTERED]"
 },"commit"=>"Register"}

(我添加了一些缩进以突出显示结构).

(i've added some indentation to highlight the structure).

如果是这样,那么您需要修改提交这些参数的表单.要么使用 form_for @user,它会自动将输入标签的 name 属性设置为 user[name], user[email] 等,或者自己手动设置字段的名称,为 user[name] 等.

If so, then you need to amend the form that submitted these params. Either use form_for @user, which will automatically set the input tags' name attributes to user[name], user[email] etc, or manually set the field's names yourself, to user[name] etc.

这篇关于参数缺失或值为空:用户 rails 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆