bwobst
bwobst

Reputation: 351

Rails 4 modal form_tag signup form on homepage

I'm getting the error "param not found: user" when trying to submit my signup form from my homepage via a modal window.

ActionController::ParameterMissing in UsersController#create
param not found: user

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

Here's the parameters that were passed in.

Parameters:

{"utf8"=>"✓",
 "authenticity_token"=>"eXXn7+Rsf4SLciRPn4RW8Lw+3u6/FJZi8IW2XxekYsU=",
 "email"=>"[email protected]",
 "password"=>"[FILTERED]",
 "password_confirmation"=>"[FILTERED]",
 "commit"=>"Sign up"}

Here's the users_controller.rb

class UsersController < ApplicationController

def new
  user = User.new
end

def create
  user = User.new(user_params)
  if user.save
    auto_login(user)
    redirect_to root_path
  else
    render :new
  end
end

    private

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

Everything looks fine to me, but obviously something is wrong. Anyone have any ideas? Thanks!

Upvotes: 1

Views: 480

Answers (1)

sites
sites

Reputation: 21795

You need to nest your params to look like this:

{
  "user" =>
    {
      "email" => ...
    }
}

To do that is easier with form_for, but you can do the same with form_tag naming your inputs:

<input name="user[email]">
<input name="user[password]">

In erb you can use:

<%= text_field_tag 'user[email]' %>

Upvotes: 1

Related Questions