简体   繁体   中英

param is missing or the value is empty: user rails 4

I am getting the following error, when i try to submit my registration form. param is missing or the value is empty: user

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

Below is the request:

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

Below is my view

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

<%= end %>

there is no params[:user] there, that's what the error is telling you. Are you perhaps expecting your params to look like this?

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

(i've added some indentation to highlight the structure).

If so, then you need to amend the form that submitted these params. Either use form_for @user , which will automatically set the input tags' name attributes to user[name] , user[email] etc, or manually set the field's names yourself, to user[name] etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM