dimanche 19 mars 2017

Rails find object id on has_many association

I'm trying to get the transaction id associated with the current_user but rails shos this error below

error:

ActiveRecord::RecordNotFound (Couldn't find Transaction with id=92 [WHERE "transactions"."user_id" = 24])

iv'e tried use where and just the transaction and with a conditional comparing the transaction.user_id with the current_user.id but show error!

someone have any hint about this kind of issue?

model user

user has_many transactions

model transaction 

transaction belongs to user


transaction controller

def new
@transaction = Transaction.new
end

def create

@transaction = Transaction.build_user

end



def show

@transaction = current_user.transactions.find(params[:id])

end

Aucun commentaire:

Enregistrer un commentaire