ruby - Association Error with Sorcery Gem in Rails -


i used sorcery set authentication in rails , i'm trying create model user id user linked reference model data entered, error:

couldn't find user without id 

it refers following code:

def create   @user = user.find(params[:user_id])   @certificate = @user.certificates.create(certificate_params)   redirect_to certificate_path(@certificate) end 

to answer basic questions i've asked myself, user logged in...

that's weird error if above code. should have gotten couldn't find bar 'id'= instead. error above given if provide no args find @ all, ie. user.find()

anyway, underlying problem here params[:user_id] doesn't contain value expect to, , contains no value @ all. haven't shown enough of other code determine why is, but doesn't matter...

unless want people able change url , add certificate other user in system shouldn't rely on params[:user_id] creating associated objects, should use current_user - that's kind of whole point of authentication.

so:

def create   @certificate = current_user.certificates.create(certificate_params)   redirect_to certificate_path(@certificate) end 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -