ruby on rails - Looping hash but showing the entire set in last loop -


i have following code in rails 3.2:

changeset: <%= @version.changeset %><br><br>  length: <%= @version.changeset.length %><br><br>  <%= @version.changeset.each_with_index |(key, value), i| %>   <%= %> - <%= key %> - <%= value %><br> <% end %> 

output is:

changeset: {"getting_there"=>["a", "b"], "description"=>["c", "d"]}  length: 2  0 - getting_there - ["a", "b"] 1 - description - ["c", "d"] {"getting_there"=>["a", "b"], "description"=>["c", "d"]} 

i have no idea why last {"getting_there"=>["a", "b"], "description"=>["c", "d"]} showing. shouldn't shown.

instead of:

<%= @version.changeset.each_with_index |(key, value), i| %> 

you need have:

<% @version.changeset.each_with_index |(key, value), i| %> 

this = means in end value of each_with_index call (which hash on call this) displayed.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -