I'm creating an app for creating multiple to-do lists. So a user signs in, has multiple lists, and each list contains multiple items. Everything else is working, but I'm struggling to create the items.
My code for creating a new item on a list (this is found in the items_controller) is :
def create
@list =
@new_item = @list.items.build(params[:item])
if @new_item.save
flash[:success] = "Item saved!"
end
redirect_to root_path
end
And the issue is, I'm not sure how to define what @list should be. I have a variable current_user (based on the session) for creating a new list, but there is only one user per session and multiple lists per session, so I can't just replicate that method.
Basically, I'm stuck on how to be able to have the item know which list it belongs to (which should be the list whose show page I was just on). In Java I'd have a static variable that I would redefine every time I went to a list, but I tried doing that and it didn't work, and I read that apparently in rails that doesn't work.