Reputation: 1375
I'm trying to use activerecord to work with a mysql database, but not in Rails. I'm not at all familiar with databases or ActiveRecord, this is just a short query I need to grab an array of the hostnames of servers from a database. I need to grab all hostnames where the Realm column equals "Stage" and the Status column equals "UP". The database is named ops and the table is host.
I've looked up ActiveRecord queries and I think that I need to do something like
Host.all(:select => "hostname", :conditions => ["realm=stage", "status=UP"])
but this seems wrong.
Can anyone help with this?
Upvotes: 0
Views: 64
Reputation: 29281
Host.where(:realm => 'stage', :status => 'UP').pluck(:hostname)
Pluck will give you an array of hostnames, which is what I think you want here.
Upvotes: 1