Ruby on Rails
Monday, November 2, 2015
On Friday, October 30, 2015 at 9:40:08 PM UTC, Ruby-Forum.com User wrote:
I have a problem with a form that either updates or creates depending on
whether the "project" exists already.
How do you want to determine whether the project exists or not?
Im using the def create
def create
puts params.inspect
@project = current_user.projects.where(id:
params[:id]).first_or_create(project_params)
[snip]
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]]
This shows that params[:id] was nil. Were you expecting that?
Fred
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/061a0e37-8d3e-4cf0-b7ed-a8b95608bea3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment