Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 %>
like image 737
theJava Avatar asked Jun 16 '14 12:06

theJava


1 Answers

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.

like image 70
Max Williams Avatar answered Nov 16 '22 22:11

Max Williams