<% newest_ticket_message = @ticket.ticket_messages.order('created_at DESC').first %>
<%= f.fields_for :ticket_messages do |tm| %>
<%# Only want to have form for updating the newest TicketMessage the user has created %>
<% next unless tm.object == newest_ticket_message %>
<%= tm.label :response %>
<%= tm.text_area :response, rows: 5, class: 'form-control' %>
<%# The default value for response_seen is true, so set it to false when setting a response %>
<%= tm.hidden_field(:response_seen, value: false) %>
<%= f.submit "Update ticket", id: 'submit', class: 'btn btn-primary' %>
<%end%>
<% @ticket.ticket_messages.each do |tm| %>
<% if tm.response != nil %>
<% cssclass = [] %>
<% if tm.response[/-----BEGIN/] %>
<% cssclass.push 'encrypted' %>
<% else %>
<% cssclass.push 'plaintext' %>
<% end %>
<%= tm.response.split("\r\n").collect{ |line| h line}.join("
").html_safe %>
<%end%>
<% if tm.message != nil %>
<% cssclass = [] %>
<% if tm.message[/-----BEGIN/] %>
<% cssclass.push 'encrypted' %>
<% else %>
<% cssclass.push 'plaintext' %>
<% end %>
<%= tm.message.split("\r\n").collect{ |line| h line}.join("
").html_safe %>
<%end%>
<%end%>