Я думаю, вам придется передать переменную index
в действие вашего контроллера как hidden_field
, а затем отобразить ее на create.js.erb
клиенты / индекс:
<% @clients.each_with_index do |client, index| %>
<div id="communication_pane<%= index %>">
<%= render client.communications.order(created_at: :desc) %>
</div>
<%= form_for([@clientlist, client, client.communications.build], remote: true) do |f| %>
<%= f.hidden_field :index, value: index %>
<%= f.text_area :content, class: "form-control", id: "communication_content#{index}" %>
<%= f.submit("New Communication") %>
<% end %>
communications_controller
def create
@index = params[:communication][:index]
...
end
Communications / create.js.erb
$('#communication_pane<%= @index %>').prepend('<%= escape_javascript(render @communications) %>');