Get random records from a has_many field in rails 3?

You can use following syntax: @hotelTheme.hotels. Order("RANDOM()"). Limit(6) #for MySQL RAND() RANDOM() is a SQL built-in function and it's works slow on big tables.

Also take a look at randumb gem.

Not sure your answer makes this quite clear. – Russell Nov 30 '11 at 14:58.

If you don't mind the overhead of returning all hotels when you only want six you could do @hotelTheme.hotels. Shuffle0..5 But if your hotel_theme has loads of hotels this is probably quite a bad idea.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions