Ask A Question

Notifications

You’re not receiving notifications from this thread.

First argument in form cannot contain nil or be empty

Samantha O asked in Rails

Hi,
I'm trying to create an account from a popup form. But I get the first argument in form cannot contain nil or be empty. What am I doing wrong?

class AccountsController < ApplicationController

    def index
  # @accounts = Account.all
end

def new
  @account = Account.new
  @account.users.build
end

def create
  @account = Account.new(account_params)

if @account.save
  sign_in @account.users.first, bypass: true
  redirect_to new_store_path
  # redirect_to dashboard_index_path
else
  render :new
  end
end

def destroy
  @account = Account.find(params[:id])
  @account.destroy
  redirect_to root_path, notice: "Account deleted."
end

private

def account_params
  params.require(:account).permit(users_attributes: [:email, :password, :password_confirmation, :role])
end
 end

<div class="modal modal--hidden">
<%= link_to root_path, class: "close-modal" do %>
<svg class="svg-icon">
  <%= svg "close" %>
</svg>
<% end %>
<header class="modal--header">
  <div></div>
  <div class="header_title">Register</div>
</header>
<div class="modal__content">

  <%= form_for @account, url: { controller: "account", action: "new" } do |f| %>
  <%= f.fields_for :users do |user| %>
  <div class="reg-form">

  <div class="inputfield">
    <%= user.hidden_field :role, value: :store_owner %>
  </div>

  <div class="inputfield">
    <%= user.email_field :email, autofocus: true, autocomplete: "email", placeholder: "name@address.com" %>
  </div>

  <div class="inputfield">
    <% if @minimum_password_length %>
      <em>(<%= @minimum_password_length %> characters minimum)</em>
    <% end %>
    <%= user.password_field :password, autocomplete: "new-password", placeholder: "Password" %>
  </div>

  <div class="inputfield">
    <%= user.password_field :password_confirmation, autocomplete: "new-password", placeholder: "Password Confirmation" %>
  </div>

  <div class="submitinputfield1">
    <%= f.submit "Sign up" %>
  </div>
</div>
<% end %>
<% end %>


Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,376+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.