2014-07-10 181 views
6

我是Rails的新手。下面的錯誤。我瞭解問題所在,但不知道如何解決問題?param丟失或值爲空

錯誤 - 參數是丟失或爲空值:客戶

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 
+1

不應將'url'指向記錄的UPDATE路徑嗎?即':url => update_my_account_details_path'?另外,你不必爲'simple_form_for'手動設置所有這些選項,下面的代碼應該可以工作:'= simple_form_for @customer,html:{class:'form-horizo​​ntal'}' – MrYoshiji

+0

'params'哈希的值是什麼也許用完整的錯誤信息/回溯來更新它?) –

+0

你的模型是怎樣的? – Mavis

回答

9

這是因爲它是未來通過爲user而不是customer。我相信這是因爲你使用的是current_user這是一個User而不是Customer(從代碼猜測)。將其更改爲params.require(:user).permit(blah)

相關問題