У меня есть форма, которая отправляет 2 поля на сервер с "remote => true"
, и в моем контроллере есть format.js
.
Если я использую значения объекта в своем create.js.erb, он работает нормально, но если я хочу отобразить включенный файл, js не сможет это сделать.
У меня есть div с идентификатором контейнер, который будет обновлен данными.
Файл create.js.erb выглядит так:
$('#container').html(<%= escape_javascript(render('index')) %>);
Мой контроллер выглядит так:
def create
@casepost = Casepost.new(params[:casepost])
respond_to do |format|
if @casepost.save
@caseposts = Casepost.all
format.html
format.js# { render json: @casepost, status: :created, location: @casepost }
else
@caseposts = Casepost.all
format.html { render action: "new" }
format.js# { render json: @casepost.errors, status: :unprocessable_entity }
end
end
end
Файл, который я хочу визуализировать, содержит содержимое массива @ caseposts.
<table>
<tr>
<th>Title</th>
<th>Body</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @caseposts.each do |casepost| %>
<tr>
<td><%= casepost.title %></td>
<td><%= casepost.body %></td>
<td><%= link_to 'Show', casepost %></td>
<td><%= link_to 'Edit', edit_casepost_path(casepost) %></td>
<td><%= link_to 'Destroy', casepost, confirm: 'Are you sure?', method: :delete %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New Casepost', new_casepost_path %>