Check if row already exists?

I’m working on a system that has a series od “bids” associated with
“posts”. Vurrently when a bid is placed I have it creating a new row
each time in the “bids” table. The bids table has id, post_id, and

The logic is to check to see if a bid already exists with a given
post_id and user_id. If it does, then just update the “amount” field. If
it doesn’t, then create a new line. Here’s what I have to create the

@post = Post.find(params[:post])
@bid =[:bid])
@bid.user_id = @session[‘user’].id
@bid.post_id =

If I try to run a find for a bid with a user_id matching the current
user I get an error about not being able to find a record with that
user_id. That’s fine, but I want to then use that result to decide if
I’m generating a new record or updating an existing one. Any ideas?

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