【发布时间】:2014-01-08 12:21:12
【问题描述】:
我在 Ruby on Rails 4 中使用 Simple_form 创建了一个部分,但是当我渲染页面时,部分中的表单标签不会环绕控件,所以当我单击提交按钮时,表单不会发布。
这是在浏览器中呈现的部分 HTML 源代码。您会注意到控件不在关闭表单标记内。
<tr data-id="4">
<form id="edit_social_platform_4" class="simple_form edit_social_platform" novalidate="novalidate" method="post" data-remote="true" action="/social_platforms/4" accept-charset="UTF-8"></form>
<td>
<div class="control-group string required social_platform_name">
</td>
<td>
<div class="control-group url optional social_platform_url">
</td>
<td>
<div class="control-group integer optional social_platform_user_id">
</td>
<td>
<input class="btn" type="submit" value="Update Social platform" name="commit">
</td>
</tr>
这里是rails中的部分代码:
<%= simple_form_for(@social_platform, remote: true) do |f| %>
<td><%= f.input :name %></td><br/>
<td><%= f.input :url %></td><br/>
<td><%= f.input :user_id %></td><br/>
<td><%= f.button :submit %></td>
<% end %>
下面是被调用的控制器更新方法的代码。这目前不运行。
def update
respond_to do |format|
if @social_platform.update(social_platform_params)
format.html { redirect_to @social_platform, notice: 'Social platform was successfully updated.' }
format.js {}
format.html { render action: 'edit' }
end
end
end
这里是将部分渲染到页面上的 update.js.erb 文件:
$('tr[data-id=<%= @social_platform.id %>]').replaceWith("<%=j render 'social_platforms/social_platforms', social_platform: @social_platform %>");
下面是部分与之交互的视图上的代码:
<table class="table socialPlatformTable">
<thead>
<tr>
<th>Name</th>
<th>Url</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody class="social-platforms">
<% @social_platforms.each do |social_platform| %>
<tr data-id="<%= social_platform.id %>">
<td><%= social_platform.name %></td>
<td><%= social_platform.url %></td>
<td><%= link_to 'Edit', edit_social_platform_path(social_platform), remote: true %></td>
<td><%= link_to 'Destroy', social_platform, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
【问题讨论】:
标签: javascript jquery ruby-on-rails-4 simple-form