Title: Rails not showing form
Tags: ruby-on-rails;ruby;ruby-on-rails-4
Question: I created a basic CRUD app using Ruby on Rails. I have created and run my migration:
class CreateUsers < ActiveRecor75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0Migration
def self.up
create_table :users do |t|
t.string :username
t.string :password
t.string :security_number
end
def self.down
drop_table :users
However, when I visit the /users/{{user_id}} page and try to create a new user, Rails doesn't provide a form for me to enter details in.
I have only been playing with Rails for real for the last few days, so I must be doing something wrong. How can I get my form for entering data?
The code for the view that is supposed to show the form:
<%= form_for(@user) do |f| %&gt;
<% if @user.errors.any? %&gt;
<div id="error_explanation"&gt;
<h2&gt;<%= pluralize(@user.errors.count, "error") %&gt; prohibited this user from being saved:</h2&gt;
<ul&gt;
<% @user.errors.full_messages.each do |message| %&gt;
<li&gt;<%= message %&gt;</li&gt;
<% end %&gt;
</ul&gt;
</div&gt;
<% end %&gt;
<div class="actions"&gt;
<%= f.submit %&gt;
</div&gt;
<% end %&gt;
I am sorry the indentation is messed.
Comment: standard rails routing should provide new model form at `/users/new` while `/users/2` should show user with id 2. Plus your form has nothing but a submit button , you might need to add a few inputs

Here is the accepted answer: Your form code is the code generated by the Rails generator, but it is missing the code to display the actual form fields.
Insert the form fields after the error messages and before the .actions div, like:
<div class="field"&gt;
<%= f.label :name %&gt;
<%= f.text_field :name %&gt;
</div&gt;


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2014:00:04/15/14', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<ruby-on-rails><ruby><ruby-on-rails-4>', 'Title': 'Rails not showing form', 'ViewCount': 50, 'id': 23084149, 'user_AboutMe': '<p>I write code and lift things.</p>\n', 'user_AccountId': 3187652.0, 'user_DisplayName': 'tjons', 'user_Reputation': 4680.0, 'user_Views': 710.0, 'user_id': 2709301.0}}