Adding new rows to a db

I’ve created the following function, and for testing have hardcoded the
following values:

def addNewRow
@timesheet = Timesheet.find(:employee_id => ‘1’,
:cost_code_id => ‘14’,
:dept => ‘007’,
:ending_date => ‘2006-07-15’)
if @timesheet == nil
Timesheet.create(:employee_id => ‘1’,
:cost_code_id => ‘14’,
:dept => ‘007’,
:ending_date => ‘2006-07-15’)
end
redirect_to_index()
end

The create code does work, but I am trying to add the find to avoid
duplicates. What is the format to mimic the where clause of a query?

Thanks!

you use conditions

:conditions =>

checkout

http://rubyonrails.org/api/classes/ActiveRecord/Base.html

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs