UsersController#create中的ActionController :: ParameterMissing [英] ActionController::ParameterMissing in UsersController#create

查看:112
本文介绍了UsersController#create中的ActionController :: ParameterMissing的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的错误页面告诉我参数缺失或值为空:用户,并引用了我的user_params私有方法和创建动作作为罪魁祸首。它还表明,我传递的所有参数都已由create post拾取。

My error page tells me "param is missing or the value is empty: user" and references my user_params private method and my create action as the culprits. It also shows that all the params I'm passing in are getting picked up by the create post.

缩写控制器:

  def new
    @user = User.new
  end

  def create
    @user = User.new(user_params)
    @user.save
    redirect_to @user
  end

  private

  def set_user
    @user = User.find(params[:id])
  end

  def user_params
    params.require(:user).permit(:first_name, :last_name, :email)
  end

启动创建帖子的form_tag:

My form_tag that initiates the create post:

= form_tag @user do
  .form-group
    = label_tag :first_name, nil, class: 'col-md-2'
    = text_field_tag :first_name, nil, class: 'col-md-3'
    %br
  .form-group
    = label_tag :last_name, nil, class: 'col-md-2'
    = text_field_tag :last_name, nil, class: 'col-md-3'
    %br
  .form-group
    = label_tag :email, nil, class: 'col-md-2'
    = email_field_tag :email, nil, class: 'col-md-3'
    %br
  .actions.form-group
    = submit_tag 'Submit', class: 'btn btn-primary col-md-offset-2'


推荐答案

更改:

= form_tag @user do

= form_for @user do |f|

然后所有 label_tag f.label text_field_tag f.text_field email_field_tag f.email_field ,最后 submit_tag f。提交。删除所有nil,一切都应该正常工作。

And then all label_tag to f.label, text_field_tag to f.text_field, email_field_tag to f.email_field and finally submit_tag to f.submit. Remove all nils and all should work.

这篇关于UsersController#create中的ActionController :: ParameterMissing的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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