I have this part of code:
<% current_user.meta_accounts.each do |meta_account| %>
<%= content_tag(:li, link_to(meta_account.name, 'javascript:void(0)')) %>
<% end %>
So, I want Rails to show all my MetaAccount
s in list, but I get this:
<li><a href="javascript:void(0)">Wallet</a></li>
<li><a href="javascript:void(0)">Credit card</a></li>
<li><a href="javascript:void(0)">Debit card</a></li>
<li><a href="javascript:void(0)">Debts</a></li>
<li><a href="javascript:void(0)">javascript:void(0)</a></li> #This is the problem
So, it also shows me MetaAccount
, which isn't created yet.
In my MetaAccounts table I have this. I'm using Postgres.
So, it also shows me the last row, where row_number is *
. I don't know why, and how to avoid this.
Thanks for any help!
Try:
<% current_user.meta_accounts.select(&:persisted?).each do |meta_account| %>
<%= content_tag(:li, link_to(meta_account.name, 'javascript:void(0)')) %>
<% end %>