开发者

Linked List Dependent Select Boxes

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:

  1. Up to 4 levels (i.e. 4 select boxes).
  2. No circular references (i.e. all previously selected items must be removed from the next text-box to be selected)
  3. Selected objects are all of the same type (requirement_level)

Any suggestions?


Since you are still getting starting, might I suggest you watch the excellent railscasts episodes? Particularly the one here:

  • http://railscasts.com/episodes/88-dynamic-select-menus

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.

  1. Ditch rjs, and use jquery client side for pretty much the whole thing. jquery really excels here. If the list of data is static, all the better, but if not you can use ajax to update things for you as you go.
  2. Look at a different UI element, perhaps a multi-select box or group of checkboxes, depending on the situation.

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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜