I have a controller action which requires to find data from existing database. I am still learning rails and recently came to know about active record queries. But I am not sure how to use it to fetch record from database in a controller action. Can anybody please explain this with some example?
Thanks in advance
I found the answer. We can use active record queries to fetch the record from the database in the controller. Example is as follow:
Consider a database 'Dress' which has color attribute. Now I want to fetch all the 'dresses' which have orange color. So the query will be as:
@dresses = Dress.where(color: 'orange')
This will fetch all the record of dresses which have color = orange.