10

I am very new at ruby - trying out rails and I am stuck already trying to do a simple register form:

<%= form_for :user, url: user_path do |f| %>
    <p>
      <%= f.label :email %><br>
      <%= f.text_field :email %>
    </p>

    <p>
      <%= f.label :password %><br>
      <%= f.password_field :password %>
    </p>

    <p>
      <%= f.submit %>
    </p>
<% end %>

This is giving an error:

No route matches {:action=>"show", :controller=>"user"} missing required keys: [:id]

Can anyone explain what this actually means?

EDIT:

I am following this tutorial, only changing posts to user: http://guides.rubyonrails.org/getting_started.html

Marty Wallace
  • 34,046
  • 53
  • 137
  • 200

2 Answers2

1

form_for should always get an object.. like a user from the controller

# controller
def new
  @user = User.new
end

# form
<%= form_for @user,...

Or you can use the form_tag method, which is not relying on an object..

BvuRVKyUVlViVIc7
  • 11,641
  • 9
  • 59
  • 111
1

I have faced a similar problem.

controller name should be plural (i.e users) and

the first line in new.html.rb should look like:

<%= form_for :user, url: users_path do |f| %>
Bala vamsi
  • 222
  • 1
  • 9