我创建了一个简单的rails应用程序: :~silil生成脚手架用户名:string email:string :〜rake db:migrate 然后编辑_form.html.erb以使用DataTable插件:
<table id="users" class="display">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Update</th>
</tr>
</thead>
<tbody>
<tr>
<%= 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 %>
<td><div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div></td>
<td><div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div></td>
<td><div class="actions">
<%= f.submit %>
</div></td>
<% end %>
</tr>
</tbody>
</table>
创建用户时,表单完全有效。但是,当我尝试更新用户的信息时,它返回一个路由错误: 没有路线匹配[POST]“/ users / 1”
对于更新,呼叫应该是PUT,但它在这里使用POST。它只发生在我使用Gem时,否则Update正常工作。 请查看以下事项。
问题链接:here
答案 0 :(得分:0)
遇到同样的问题。不得不使用:include_id => false
来解决它,以便rails不生成隐藏的:id
字段,然后在其中一个td中手动添加隐藏字段。