Validate select list

Hi,

I have two database - tables (users and user_permissions) which have a
1…n - relationship. If I want to create a new entry on ‘users’ table I
need the correct user_permission_id from the other table. So the form
which I use has a select list with all entries of the user_permissions -
table but if anybody insert an invalid key into the select list I get
inconsistent data in my database. How can I solve this problem?

At this time I use “validates_inclusion_of” and “validates_associated”
to solve this problem but without any success.

Eddy

Hi Eddy,

Eddy B. wrote:

I have two database - tables (users and user_permissions)
which have a 1…n - relationship. If I want to create a new
entry on ‘users’ table I need the correct user_permission_id
from the other table. So the form which I use has a select
list with all entries of the user_permissions - table but if
anybody insert an invalid key into the select list I get
inconsistent data in my database. How can I solve this
problem?

The ‘standard’ approach to this is to put an ‘observe_field’ on the
first
select field which fires a method that, based on the value selected,
re-renders (typically with RJS) the second select. If you’re new to
RJS,
Cody F.'s piece at O’Reilly is we’ll worth the $10.

HTH,
Bill

Hi Bill,

thanks for your post but I looking for a solution for my ‘user’ model
which allows me to validate the user_permission_id with all entry of the
user_permissions - table. Has anybody a solution or a tip for my
problem?

Eddy

On 12 Jun 2008, at 12:48, Eddy B. wrote:

inconsistent data in my database. How can I solve this problem?

I would just use a foreign key.

Fred