目前,我有一个 6 模型的 ruby on rails 应用程序,我添加了 authlogic。整体设置是
User :has_many categories, topics,messages
Categories has_many topics,
Topics has_many messages
(有和对应的对立的belongs_to 链接)。
当我尝试访问 current_user.categories.find(2) 时,控制器中没有返回任何结果。
此外,当我尝试运行它时
current_user.topics.find(params[:topic_id]).messages.build
然后,
@msg = current_user.messages.build(params[:message])
@msg.save
它不会从 has_many 中保存 user_id。
在添加 current_user 指令之前,该程序的所有功能都可以正常工作。
我在设置上犯了错误吗?还是执行?
因为在构建后关联没有保存,我以后可以在模型中添加 user_id 字段吗?
抱歉所有问题,并在此先感谢。