Rails 协会/会议问题
我正在开发一款应用程序,供我的孩子们记录他们的家务活。我有 3 个孩子(Nick、Siena、Mac),并且有一个主页,每个名字都带有超链接...
我有以下关联:
Child:
has_many :completions
has_many :chores, :through=>:completion
Completion:
belongs_to :child
belongs_to :chore
Chore:
has_many :completions
has_many :kid, :through=>:completion
如何(单击孩子的名字后)将 child_id 保存为会话对象将补全信息发布到补全模型?
当另一个孩子在主页中点击他们的名字时,如何清除/更改该会话到新的孩子?
非常感谢任何帮助。谢谢,CB
I am working on a app for my kids to log their chores. I have 3 children (Nick, Siena, Mac) and have a home page with each name hyperlinked ...
I have the following associations:
Child:
has_many :completions
has_many :chores, :through=>:completion
Completion:
belongs_to :child
belongs_to :chore
Chore:
has_many :completions
has_many :kid, :through=>:completion
How do I (upon clicking the child's name) save the child_id as a session object for posting completions to the completions models?
How do I clear / change that sesison to a new child when another child clicks their name in the homepage?
Any help is greatly appreciated. Thanks, CB
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所以乔希超越了。作为一个菜鸟,我问的问题对于大多数人来说更加简单和基本。答案非常简单:
这允许我将孩子的 ID 存储在会话中并发布到已完成的模型中。
So josh went above and beyond. As a noob i was asking something much more simple and elementary for most folks. The answer was quite simple:
This allowed me to store that child's id in a session and post to the completed model.
如果我正确理解了这个问题(至少按照您的评论中的描述),我最近做了类似的事情。请参阅从多个父对象构建嵌套属性。基本上,我使用 polymorphic_url 建立一个链接来创建一个新项目(我可能会使用 @child.chores.build(params))并传递属性:chore_id,即
在您的控制器中确保您的 ChoresController#new 具有 希望这会有所
帮助。
If I understand the question correctly (at least as described in your comment), I did something similar recently. See Building a nested attribute from multiple parent objects. Basically, I used polymorphic_url to make a link to create a new item (I would probably use @child.chores.build(params)) and pass the attribute :chore_id, i.e.
In your controller make sure that for your ChoresController#new you have something like
Hope this helps.