Here is the situation
- User has_many Posts
- User has_many Replies
- Post has_many Replies
Problem is when I add new reply using
@reply = current_user.posts.find(params[:post_id]).replies.new(params[:reply])
In the Replies it only saves the post_id and user_id is null, and if I used current_user.replies.new(params[:reply]) to save the post I get user_id but post_id becomes null
So how to add a reply to have reference for both post_id and user_id? Anyone got a clue!
Maybe your association like this:
User Model
Post Model
Reply Model
So, you can find a post:
Add new reply to post: