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

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -