加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 缺少param或值为空

发布时间:2020-12-16 20:52:22 所属栏目:百科 来源:网络整理
导读:我是Rails的新手.得到以下错误.我明白这个问题是什么,但不确定如何修复它? 错误 – 参数丢失或值为空:客户 def customer_params params.require(:customer).permit( :first_name,:last_name,:email,:password,:password_confirmation) end end DetailsCont
我是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,: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

解决方法

这是因为它是作为用户而不是客户而来的.我认为是因为您使用的是current_user,它是用户而不是客户(从代码中猜测).将其更改为params.require(:user).permit(blah)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读