2017-09-25 56 views
0

我使用的是设计宝石,我用它来创建一个基本的用户模型。之后,我添加了一个“phone_number”字段,我希望能够编辑另一个控制器中的phone_number字段。我已经设置了控制器的形式编辑的电话号码的方法是这样的:rails 5参数丢失或值为空:phone_number

仪表盘控制器

class DashboardController < ApplicationController 

    # So that we don't have to authenticate users for only the home action in this controller 
    skip_before_action :authenticate_user!, :only => [:home] 

    def home 
    current_user.update(user_params) 

    respond_to do |format| 
     if current_user.update_attributes(user_params) 
     format.html { redirect_to current_user, notice: 'User was successfully created.' } 
     else 
     format.html { redirect_to current_user, notice: 'Errors.' } 
     end 
    end 

    end 

    private 

    def user_params 
    params.require(:user).permit(:phone_number) 
    end 
end 

我的形式是:

<%= form_for(current_user) do |f| %> 
     <%= devise_error_messages! %> 
     <div class="field"> 
      <%= f.label :phone_number %><br /> 
      <%= f.text_field :phone_number, autofocus: true %> 
     </div> 

<% end %> 

眼下,这家方法这个控制器被路由到我的根页面(所以一旦你打localhost:3000,它将访问这个家庭控制器。

不幸的是,页面甚至没有加载和错误负载,我得到的是:

的ActionController :: ParameterMissing在DashboardController#家

参数是丢失或为空值:用户

我怎样才能建立一个形式,我控制台控制器让current_user编辑他们的电话号码字段?在此先感谢

+0

请发布日志。 – Pavan

回答

0

当你去localhost:3000你没有提供任何参数,可以,但你的控制器期望PARAMS [:用户]:

def user_params 
    params.require(:user).permit(:phone_number) 
    end 

这就是为什么你的错误。您可能不希望将您的根路由到此#home操作。

相关问题