gpt4 book ai didi

ruby-on-rails - 参数缺失或值为空

转载 作者:数据小太阳 更新时间:2023-10-29 07:04:39 26 4
gpt4 key购买 nike

我是 Rails 新手。得到下面的错误。我了解问题所在,但不确定如何解决?

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

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

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)

关于ruby-on-rails - 参数缺失或值为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24681280/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com