Conditional search in Ruby On Rails



For Conditional search in ror

I have the following model:

  create_table "users", :force => true do |t|
    t
.string   "name"
    t
.string   "url"
    t
.integer  "clicks_given"
    t
.integer  "clicks_received"
    t
.datetime "created_at"
    t
.datetime "updated_at"
 
end

and I have defined this method for the model:

  def credits
    credits
= self.clicks_given - self.clicks_received
 
end

Pass the condition as an array instead of a hash:



@users = User.find(:all, :conditions => [ "clicks_given - clicks_received >= ?", -5 ])


Comments

Popular posts from this blog

Rails Memcache issues

Enabling password authentication for new ec2 box | ssh, ssh config, EC2 setup, new user in EC2, PasswordAuthentication

What's the difference between "include" and "require" in Ruby?