0
我已經在Ruby on Rails 4中創建了一個使用Simple_form的部分,但是當我渲染頁面時,部分中的表單標籤不包圍控件,因此當我點擊提交按鈕,表單不會發布。Rails簡單形式<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>
以下是在軌道的部分的代碼:
<%= 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>
謝謝Orbig。很有幫助。 – miggitty