I’m in need of some assistance with Ruby on Rails and Sqlite3.
This is what I did four times:
<%= Bullet.select(:content).order('random()').limit(1).collect { |b| b.content } %>
But instead of four different random “bullets” it will do four of the same bullets chosen randomly from the list of bullets I have.
I also have tried select * from bullets order by random() limit 4; in sqlite3 (using the program sqliteman) and have also done select * from bullets order by random() limit 1; four times.
Any idea on how I can do this successfully in Ruby on Rails by accessing the database table and using embedded ruby (.erb)?
I’m a bit of a newbie, so I’ll need to know where to put what. (e.g. the file I’m displaying the bullet content pulled is show.html.erb, and its controller is students_controller.rb | I am also using sqliteman so I’ll need to know if I do anything with that.)
Try this now:
EDIT
This new method will get the
random_bulletsarray, shuffle it and get the 4 first bullets.This way, it would be always different bullets.