0

As you can see below, I am having a problem of getting extra spaces in my search result. As you see in the photo, between the numbers and the elements, I am getting spaces and I do not why?

<td>
    <% saved_element = ""%>
    <% sensor.base_material.elests.each_with_index do |elest, v| %>
      <% if elest.element.include? "O" %>   
        <% saved_element = elest %>
      <% else %>
        <%= elest.element.split('-').last %>
        <% if elest.stoich != 1 %>
            <sub><%= elest.stoich.to_i %></sub>
        <% end %>
      <% end %>
    <% end %>
    <% if saved_element.present? %> 
        <%= saved_element.element.split('-').last%>
        <% if saved_element.stoich != 1 %>
            <sub><%= saved_element.stoich.to_i %></sub>
        <% end %>
    <% end %>
</td>

Results of search

YLim
  • 255
  • 1
  • 8
  • 3
    What does the *HTML (as source text)* look like and what *styles* are applied? It should be possible to reproduce the issue in a fiddle *without* the Ruby code at all; then it can be worked backward to 'where' the spaces come from. Even if there are no spaces (and I suspect this is the 'simple issue'), styling can still result in unexpected rendering. – user2864740 Nov 22 '19 at 20:44
  • 2
    Annnnyway, I would pull the generation of the [HTML] representation outside of the view. This will make it simpler and easier to eliminate extra spaces. (It could also be replaced later with SVG or whatnot in a self-contained manner.) The view then would only contain the loop generating the table; not the rendering of the value therein. – user2864740 Nov 22 '19 at 20:49
  • 2
    Try using `-%>` to avoid adding line breaks. See https://stackoverflow.com/questions/7996695/what-is-the-difference-between-and-in-erb-in-rails Or try [Slim](http://slim-lang.com/). – Schwern Nov 22 '19 at 20:58
  • 1
    Thats way to much complexity for a view. I would really extract that code into a helper and use the rails `tag` helper`. Much easier to test and much easier to read then a tangled mess of erb tags. – max Nov 22 '19 at 21:29

0 Answers0