Now, we will learn various methods available in Rhom for CRUD operation. Generally, we need to Create, Read, Update, and Delete an object of a model. Rhom provides various helper methods to carry out these operations:
delete_all
: deletes all the rows that satisfy the given conditions.Employee.delete_all(:conditions => {gender=>'Male'})
The above command will delete all the male employees.
destroy
: this destroys the Rhom object that is selected.@employee = Employee.find(:all).first @employee.destroy
This will delete the first object of employees, which is stored in
@employee
variable.find
: this returns Rhom object(s) based on arguments.We can pass the following arguments:
:conditions
: this is optional and is a hash of attribute/values to match with (i.e.{'name' => 'John'}
):order
: it is an optional attribute that is used to order the list:orderdir
: it is an optional...