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 = Hash.new if condition1 find_hash[ :all ] = true ???? else find_hash[ :first ] = true ???? end .... users.find( find_hash ) thank -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
aleksey.eschenko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Oct-15 09:39 UTC
Re: create hash before model.find( _your_created_hash_ )
"George писал(а): "> 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 = Hash.new > if condition1 > find_hash[ :all ] = true ???? > else > find_hash[ :first ] = true ???? > end > > > .... > > users.find( find_hash ) > > thank > > -- > Posted via http://www.ruby-forum.com/.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 else find_params[0] = :first end all other options, such as limit, group or include should be placed in the options hash, e.g. find_params[1] = {:include => :posts, :limit => 10} then the find method is called in this way: users.find(*find_params) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---