Re: [Rails] add user_id to new record

2020-03-10 Thread fugee ohu
On Monday, March 2, 2020 at 7:47:37 AM UTC-5, Walter Lee Davis wrote: > > In your Controller's #new and #create methods, scope the post to be owned > by the current_user (or whatever other scheme you may be using for your > logged-in-user management). > > def new > @post =

Re: [Rails] add user_id to new record

2020-03-02 Thread Walter Lee Davis
In your Controller's #new and #create methods, scope the post to be owned by the current_user (or whatever other scheme you may be using for your logged-in-user management). def new @post = current_user.posts.build end def create @post = current_user.posts.create(post_params) ... end

[Rails] add user_id to new record

2020-03-01 Thread fugee ohu
How do i add user_id to a new record without placing it in a form as a hidden field? I tried adding in the controller's create action just before `if @post.save?` but that didn't cause new records created to have a value for user_id Maybe it was because I'm using a nested form and this record