链接列表相关选择框
所以我这样做的时间不长,但我完全坚持下去。我有一个如下所示的模型(为简洁起见进行了简化):
class ReqBreakdown < ActiveRecord::Base
belongs_to :next_level #nil if lowest level
belongs_to :previous_level #nil if highest level
belongs_to :requirement_level
end
我需要一种从 UI 构建这些列表的方法。我最初设想使用链接的下拉菜单,如下所述: http://blog.jatinder.me/2006/09/cascading-select-boxes-with-rjs.html 但我什至无法让它在我的控制器上调用操作。我将描述的 javascript 复制到我的 application.js 中,确保它包含在我的布局中,将帮助器添加到 application_helper.rb 中,并将支持操作添加到我的控制器中,但没有运气。老实说,我什至不确定它是否能满足我的要求。 选择规则为:
- 最多 4 个级别(即 4 个选择框)。
- 没有循环引用(即必须从下一个要选择的文本框中删除所有先前选择的项目)
- 所选对象都是同一类型(requirement_level)
有什么建议吗?
So I haven't been doing this for long but I'm completely stuck on this. I have a model which looks like this (simplified for brevity):
class ReqBreakdown < ActiveRecord::Base
belongs_to :next_level #nil if lowest level
belongs_to :previous_level #nil if highest level
belongs_to :requirement_level
end
I need a way to build these lists from the UI. I had initially envisioned using linked drop-downs like those described here: http://blog.jatinder.me/2006/09/cascading-select-boxes-with-rjs.html but I can't even get it to call the action on my controller. I copied the described javascript into my application.js, made sure it was included in my layout, added the helper to application_helper.rb, and added the supporting actions to my controller, but no luck. Honestly, I'm not even sure it will meet my requirements.
The rules for selection are:
- Up to 4 levels (i.e. 4 select boxes).
- No circular references (i.e. all previously selected items must be removed from the next text-box to be selected)
- Selected objects are all of the same type (requirement_level)
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
既然您还处于起步阶段,我可以建议您观看精彩的 Railscasts 剧集吗?特别是这里的一个:
我知道这可能不是您正在寻找的答案,但是由于您在连接控制器以执行您想要的任何操作时遇到困难,因此您的问题可能真的在任何地方。 Ryan(railscasts 的作者)很好地解释了这些小东西,并为他的所有剧集提供了完整的源代码。
如果这是我,我可能会做两件事之一。
我对你正在寻找的方向没有问题,但由于你对这个问题的技术细节有点了解,我实际上只是提供一些一般性建议,而不是具体的答案。
祝你好运!
Since you are still getting starting, might I suggest you watch the excellent railscasts episodes? Particularly the one here:
I know this may not be the answer you are looking for, but since you are having trouble getting your controller hooked up to do anything you want, your issue could really be anywhere. Ryan (author of railscasts) does a great job explaining the small stuff, as well as providing full source code to all his episodes.
If this were me, I would probably do one of two things.
I have no problem with the direction you are looking but since you are a bit light on technical details for the question, I'm really just giving some general advice rather than a specific answer.
Good luck!