/ Published in: Rails
in your model, add a def to pick a record where an option (in my case lenght) is equal to 1
- def self.random
- ids = connection.select_all("SELECT id FROM paragraphs WHERE length = 1")
- find(ids[rand(ids.length)]["id"].to_i) unless ids.blank?
You need to login to post a comment.