Validating uniqueness within a scope

(under former subject line "Re: [Rails] Re: Validate in a model using a controller def", now overly polluted with off-topic junk):

JavierQQ, try this:

validates :qnumber, :uniqueness => \{ :scope => :evaluation\_id,
    :message => "must be unique within each evaluation" \}

in the model, and let us know what happens. Don't worry about what controller it's going through to get there.


It works! ... well as far as I tested :), thanks a lot

You're welcome, I'm glad it works. I haven't actually used something like that, but the general technique of how I found it may be useful to you: just take the important keywords, and Google them together. IIRC, what I looked for was "rails validates uniqueness scope" (without the quotes). What I suggested above was basically just trying to cast your needs (as I understood them) into the syntax I saw. Google-fu is a skill that will serve you well in many areas.

Another approach you might want to try is: make the question ordering use drag and drop, with the user never seeing any question numbers. Just apply the numbers yourself when the user wants to save the evaluation. That will be a much more intuitive and less frustrating user experience, especially on large evaluations so that you'd have to renumber a lot of questions. That will also be a good way for you to explore some great UI tricks you can use again later.

I've been reading the messages about top-posting and I'm really really sorry about any trouble I could have caused

Don't worry, it wasn't your fault.