2014-07-10 131 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)

相关问题