0

I have this code in on of my views

<%= @quotes.each do |f| %>
   <%=f[:underwriter]%>: £<%=f[:premium]%>
   <br>
<% end %>

And in my controller I pass it the argument

 @quotes = [{underwriter:"dtc",premium:500},{underwriter:"abc",premium:800}]

I expect it to print out the underwriter and premium, which it does, however it tags the whole array on at the end for some reason. This is shown below

dtc: £500 
abc: £800 
[{:underwriter=>"dtc", :premium=>500}, {:underwriter=>"abc", :premium=>800}]

Anyone can enlighten my to what is causing this behaviour?

DTC
  • 87
  • 2
  • 8

1 Answers1

2

Just do

<% @quotes.each do |f| %>
   <%=f[:underwriter]%>: £<%=f[:premium]%>
   <br>
<% end %>

Array#each - Calls the given block once for each element in self, passing that element as a parameter. when iteartion completed, return the self. <%= %> prints what is in between inside the tag into erb file, whereas <% %> executes the ruby code within the brackets.

Check this one Rails, ERB syntax also.

Community
  • 1
  • 1
Arup Rakshit
  • 116,827
  • 30
  • 260
  • 317