以下字段 1.Name 2.gender 3.price 4.email 5.payment
全部存储在数据库中。但是购买日期不存储在数据库中。所有字段都显示在编辑用户表单中,但不显示购买日期。
_form.html.erb
<%= form_for(@user, :html => {:multipart => true}) 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="container-fluid">
<div class="content">
<div class="row">
<div class="col-md-6">
<div class="well well-sm">
<form class="form-inline" role="form">
<fieldset>
<legend class="text-center header">New user</legend>
<div class="form-group">
<div class="col-md-8">
<%= f.label :name %>
<%= f.text_field :name %>
</div>
</div>
<div class="form-group">
<div class="col-md-8">
<%= f.label :email %>
<%= f.text_field :email %>
</div>
</div>
<div class="form-group">
<div class="col-md-8">
<%= f.label :price %>
<%= f.text_field :price %>
</div>
</div>
<div class="form-group">
<div class="col-md-8 gender">
Gender:<br>
<%= f.radio_button(:gender, "Male")%>
<%= f.label(:gender_option1, "Male") %>
<%= f.radio_button(:gender, "Female")%>
<%= f.label(:gender_option2, "Female") %>
</div>
</div>
<div class="form-group">
<div class="col-md-8 gender">
Payment:<br>
<%= f.check_box(:payment) %>
<%= f.label(:Debitcard )%>
<%= f.check_box(:payment)%>
<%= f.label(:Creditcard) %>
<%= f.check_box(:payment) %>
<%= f.label(:cashondelivery)%>
</div>
</div>
<div class="form-group">
<div class="col-md-8">
<%= f.label :image %><br />
<%= f.file_field :image %>
</div>
</div>
<div class="form-group">
<div class="col-md-8">
<%= f.label :purchasedate %><br />
<%= f.text_field :purchasedate ,:value => @purchasedate %>
</div>
</div>
<div class="form-group">
<div class="col-md-12 text-center">
<%= f.submit %>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<% end %>
schema.rb
create_table "users", :force => true do |t|
t.string "name"
t.string "email"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
t.string "gender"
t.integer "price"
t.string "payment"
t.date "purchasedate"
end
end
**购买日期**
<div class="col-md-8">
<%= f.label :purchasedate %><br />
<%= f.text_field :purchasedate ,:value => @purchasedate %>
![enter image description here][1] </div>
我想将购买日期存储在数据库中,并且它的值显示在“编辑用户”表单中。请帮帮我。
答案 0 :(得分:0)
<%= f.text_field :purchasedate ,:value => @purchasedate %>
使用:value => @user.purchasedate
代替:value => @purchasedate