I'm new to rails and working through a tutorial. I have created a scaffold and a db, but when I run my site the model attributes are hidden (only one). Is this an issue I can fix or a biproduct of a bad setup?
$ rails generate scaffold User name:string email:string
I've tried this a few (underestimate) times so I have added a step to remove the prev db
$ bundle exec rake db:drop
$ bundle exec rake db:migrate
$ rail s
When I visit /users/new/
I see a form without input fields. Any idea why this is?
When I go into the html of the page it says that the attribute name is hidden, but there is no sign of email.
Any ideas?
Response to Comments
users/_form.html.erb
<%= form_for(@user) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
schema.rb
ActiveRecord::Schema.define(version: 20131104084139) do
create_table "users", force: true do |t|
t.datetime "created_at"
t.datetime "updated_at"
end
end
You don't have either name or email input fields in your form, hence you see a blank form.
Add the following before <div class="actions">
<p>
<%=f.label :name%>
<%=f.text_field :name%>
</p>
<p>
<%=f.label :email%>
<%=f.text_field :email%>
</p>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.