views:

304

answers:

1

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?

+1  A: 

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.

  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!

dpb
thanks, I'm taking a look at this. Another noob question though, this time about javascript. In that particular RailsCast his javascript includes the call: $('element_id').getValue() //element_id is a select tagwhen getting the value out of the select tag. However, that doesn't appear to be valid javascript, at least as far as Firebug is concerned. Am I missing something or is this not right?
Matt Baker
In that railscasts he is using the prototype library, which provides this feature. I'm way more familiar with jquery, but they both have a similar notion of being able to select things in the dom via ID or CSS class. Look here: http://api.prototypejs.org/dom/dollar.html The `$$` function does this same thing for classes in prototype world. Basically, you select something with `$` or `$$` and then operate on it with method like hide, show, etc. prototype and jquery are both laguages of sorts in themselves, but **well** worth the time invested to learn them.
dpb