Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

ruby on rails - param is missing or the value is empty

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

 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

View

 .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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...