I'm on Rails 4 using SQLite, and I have a database of 75,000 quotes. I would like to grab a random record (quote) from this database and display it for users to see. I've looked around but no method I have searched around here has worked yet. Here's code that grabs the first record and displays it:
<% Quote.limit(1).all.each do |quote| %>
<%= quote.quote %> :: <%= quote.author %> :: <%= quote.genre %>
I have also tried the following method, but this returns a long alphanumeric value rather than the quote.
offset = rand(Quote.count)
rand_record = Quote.offset(offset).first
Thanks!
Aucun commentaire:
Enregistrer un commentaire