theJava
theJava

Reputation: 15044

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"=>"[email protected]",
 "password"=>"[FILTERED]",
 "confirm_password"=>"[FILTERED]",
 "commit"=>"Register"}

Below is my view

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

<%= end %>

Upvotes: 25

Views: 45744

Answers (1)

Max Williams
Max Williams

Reputation: 32945

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"=>"[email protected]",
            "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.

Upvotes: 23

Related Questions