views:

65

answers:

1

Dear All,

I need to apply a regular expression in html.erb

<% taxon_name.strains.each do |strain| %>
<% taxon_name.strain_appendices.each_with_index do |strain_appendice, i| %>
<% if ((strain_appendice.data_source =~ /LPSN/) && (strain.relevance =~ /^ty(.*)ain$/))%>
<% if i == 0 %>
<p><%= strain_appendice.appendix %>  </p> <% strain.strain_id %> <% strain.relevance %>
<%else%>
<%= strain_appendice.appendix %> - <% strain.strain_id %> <% strain.relevance %>
<%end%>
<%end%>

This code replaces the all content of a strain.strain_id & strain.relevance and doesnot passes match criteria. Instead of matching it replacing strain.strain_id & strain.relevance contents.

Kindly tell me the way to match and pass conditions.

-- With Regards,

Palani Kannan. K,

+1  A: 

This code is working for me if I add two <%end%> statements at the end, like this:

<% taxon_name.strains.each do |strain| %>
  <% taxon_name.strain_appendices.each_with_index do |strain_appendice, i| %>
    <% if ((strain_appendice.data_source =~ /LPSN/) && (strain.relevance =~ /^ty(.*)ain$/))%>
      <% if i == 0 %>
        <p><%= strain_appendice.appendix %>  </p> <%= strain.strain_id %> <%= strain.relevance %>
      <%else%>
        <%= strain_appendice.appendix %> - <%= strain.strain_id %> <%= strain.relevance %>
      <% end %>
    <% end %>
  <%end%>
<%end%>
Matt
**Two** additional `end` tags. If it doesn't work, maybe your data doesn't match the regexp. I tested this code with data that matched and it worked.
Matt
@Matt: You are correct... its working,, Tanx.
Palani Kannan