[Help] Need help with first_or_create. Never finds existing Record

I have a problem with a form that either updates or creates depending on
whether the “project” exists already.

Im using the def create

def create
puts params.inspect
@project = current_user.projects.where(id:
params[:id]).first_or_create(project_params)
puts params.inspect
if @project.save
flash[:success] = “Project created!”
redirect_to root_url
else
flash[:success] = “Project not created!”
redirect_to root_url
end
end

Problem is it never finds the existing record.

generated SQL is

SELECT “projects”.* FROM “projects” WHERE “projects”.“user_id” = ? AND
“projects”.“id” IS NULL ORDER BY “projects”.“created_at” DESC LIMIT 1
[[“user_id”, 1]]
Im sending the parameters in wrong but i’m not sure of the solution.

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