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
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..
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| %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With