ruby on rails - Cannot find User with provided user_id parameter -


i'm pretty new rails , trying learn framework creating twitter clone app. can`t understand error message code more or less same 1 have in sessions controller. i'm trying save new post in db , redirect users show page.

so here's code:

def create     @user = user.find(params[:user_id])     @post = post.new(posts_params)      if @post.save         redirect_to @user , notice: "you have written new tweet" 

my error message:

activerecord::recordnotfound in postscontroller#create couldn't find user without id

the tweets saved in db. i'm having problems redirect. works when write in id manually though.

this because not sending user_id post requests. pretty sure tweet not associated user now. have use authentication library such devise persist user login.

if use library, can use current_user method instead of doing

@user = user.find(params[:user_id] 

doing above code not because can manipulate user_id in post form data post tweet user. if have question, please comment :)


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -