参数缺失或值为空 [英] param is missing or the value is empty

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

问题描述

我是 Rails 的新手.得到下面的错误.我明白问题是什么,但不知道如何解决?

I am new to Rails. Getting the error below. I understand what the issue is, but not sure how to fix it?

错误 - 参数缺失或值为空:客户

Error - param is missing or the value is empty: customer

  def customer_params
      params.require(:customer).permit(
        :first_name, 
        :last_name, 
        :email, 
        :password, 
        :password_confirmation)
    end
   end

DetailsController.rb

DetailsController.rb

 class My::Account::DetailsController < MyController

 def show
   @customer = current_user
 end

 def update
   @customer = current_user
   @customer.update_attributes(customer_params)
   if @customer.errors.any?
     render :action => :show
   else
     redirect_to my_account_details_path, :notice => 'Account details updated'
   end
    end

   private

   def customer_params
      params.require(:customer).permit(
        :first_name, 
        :last_name, 
        :email, 
        :password, 
        :password_confirmation)
    end
   end

查看

 .account.container
.row
    = render :partial => '/my/account/sidebar'
    .section
        %h2 Your account details

        = simple_form_for @customer, :url => my_account_details_path, :method => :put, :html => { :class => 'form-horizontal'} do |form|
            .field
                = form.input :first_name

            .field
                = form.input :last_name

            .field
                = form.input :email, :as => :email

            %hr
            %h4 Leave password fields blank to keep the existing password
            %hr

            .field
                = form.input :password, :input_html => { :value => '' }
            .field
                = form.input :password_confirmation, :input_html => { :value => '' }

            .field-actions
                %button.btn.btn-primary{type: "submit"} Save

推荐答案

这是因为它是以 user 而不是 customer 的身份通过的.我相信这是因为您使用的是 current_user ,它是一个 User 而不是 Customer (从代码中猜测).将其更改为 params.require(:user).permit(blah)

It is because it is coming through as user and not customer. Which I believe is because you are using current_user which is a User and not a Customer (guessing from the code). Change it to be params.require(:user).permit(blah)

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

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