I’m using the code:
<h2>
<% random_bullets = Bullet.all %>
<ul>
<% random_bullets.shuffle.first(4).each do |r| %>
<br>
<li><%= db.save(r.content) %></li>
<% end %>
</ul>
</h2>
to pull four random bullets from my db and post them to a page; what I’m trying to do is get them to save the bullets so they’re only randomized after the page is generated. Is there anything I can do to this code to achieve this? If not, what can I do to achieve this. The code is in embedded Ruby and the db is a sqlite3 database.
Setting random bullets and randomising belongs in your controller. Once there I recommend setting a cookie which contains an array of bullet.ids in order.
Then you can just iterate over the array if it exists else create a new one and save it.
In your controller:
in your view:
Are you aware that it’s invalid html to put a
<ul>within a<h2>or to put a<br>within a<ul>?