Create hash before model.find( _your_created_hash_ )

Maybe I should ask this in Ruby forum.
Can anybody tell me how to create a hash before invoke the ‘find’ method
and use this hash as parameter for the method?

Smt like:

find_hash =
if condition1
find_hash[ :all ] = true ???
find_hash[ :first ] = true ???

users.find( find_hash )


"George писал(а):

find_hash[ :first ] = true ???
Posted via
find() accepts options hash as a second optional parameter. :first or
:all symbol is a method parameter, not a hash value. What you need is:
find_params = []
if condition1
find_params[0] = :all
find_params[0] = :first

all other options, such as limit, group or include should be placed in
the options hash, e.g. find_params[1] = {:include => :posts, :limit =>

then the find method is called in this way: users.find(*find_params)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs