簡體   English   中英

param丟失或值為空:user rails 4

[英]param is missing or the value is empty: user rails 4

當我嘗試提交我的注冊表單時,我收到以下錯誤。 param丟失或值為空:user

def user_params
   params.require(:user).permit(:name, :email, :password, :password_confirmation)
end

以下是要求:

{"utf8"=>"✓",
 "authenticity_token"=>"YX0+4AeWlGWJiQZgbhV9cxi6TUCoibZfwh95BrK9iCQ=",
 "name"=>"asasa",
 "email"=>"asasas@asas.com",
 "password"=>"[FILTERED]",
 "confirm_password"=>"[FILTERED]",
 "commit"=>"Register"}

以下是我的觀點

<%= form_tag users_path, class: "form-horizontal", id: "signupform" do %>

<%= end %>

那里沒有params[:user] ,這就是錯誤告訴你的。 您是否希望您的參數看起來像這樣?

{"utf8"=>"✓",
 "authenticity_token"=>"YX0+4AeWlGWJiQZgbhV9cxi6TUCoibZfwh95BrK9iCQ=",
 "user" => {"name"=>"asasa",
            "email"=>"asasas@asas.com",
            "password"=>"[FILTERED]",
            "confirm_password"=>"[FILTERED]"
 },"commit"=>"Register"}

(我添加了一些縮進以突出顯示結構)。

如果是這樣,那么你需要修改提交這些參數的表格。 使用form_for @user ,它會自動將輸入標簽的name屬性設置為user[name]user[email]等,或者自己手動設置字段名稱, user[name]等。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM