i am pretty new to RoR so this might be a newbie question but i couldn't find an answer to it and solve the problem. I need to check every single element from a dynamic array (which is created by a HABTM connection over a join table) for a condition.
Right now i have something like this:
scope :filter, lambda { |devicefilter, testtypefilter|
{
testtypefilter.each { |testtype|
:include => :tests,
:conditions => ['(tests.device != ? OR tests.device IS ?) AND ? NOT IN tests.testtypes', devicefilter, nil, testtype]
}
}
}
This shows me a syntax error. But i think even if i manage to get it working this way it would not perform the sql query correctly since ts and tts is connected by HABTM, so the actualy value in the table is NULL and i would have to create another join in that query. I have really no clue how to solve this. Any hints would be helpful.
Thanks, Niko
Edit: My Controller looks like this
if params[:d] == nil or params[:t] == nil
@users = User.all
else
@users = User.filter(params[:d], params[:t])
end
:d is a fixed value which is comming from a select_tag :t is an array which is comming from a bunch of dynamic checkboxes
the values are all fine and being passed correctly to the Model. So the view or controller shouldn't be the problem.
Edit2: Since it looks a bit unclear, here is the current situation: There is a form which consists of a Select-Box and a bunch of Checkboxes. The Select-Box is getting its values from the table "devices" and after the form is submitted it passes the selected value to the controller as the param :d. The Checkboxes are a list from all entries of the table "testtypes" and after the form is submitted it passes an array of all checked testtype_ids from the table to the controller as the param :t. (works correctly)
Now there is another table "tests" which has a HABTM connection to all entries in devices and testtypes, so i can gather special connections from 1 device and and multiple testtypes together in a single entry.
Now in the table "users" there is a column "tests" which refers to the table "tests" in a HABTM connection so 1 user can have (participated in) multiple tests (which can have multiple testtypes).
So after the form is submitted the values :d and :t should be used for a sql query to filter all users by tests (while tests are dependant by devices and testtypes). So all users should by checked in the column tests by the values of the referring tests in devices (:d) and testtypes (:t[]).
But since testtypes (:t[]) is being passed as an array i have to check somehow every single element of that array with a sql request. Or is there a way to check for the whole array?
Example:
There are 3 Devices: (dynamic table)
A01
A02
A03
There are 3 Testtypes: (dynamic table)
TT01
TT02
TT03
There are 4 Tests: (dynamic table with HABTM devices and testtypes)
T1 = A01 - TT01/TT03
T2 = A01 - TT03
T3 = A02 - TT02/TT03
T4 = A03 - TT01/TT02/TT03
There are 5 Users: (dynamic table with HABTM tests)
U1 = ... T1 ...
U2 = ... T2/T4 ...
U3 = ... T3/T4 ...
U4 = ... T1/T2/T3 ...
U5 = ... T3/T4 ...
Now the Form will look like:
Device: Select-Box={A01/A02/A03}
Testtypes: Checkboxes={TT01/TT02/TT03}
If i select now A01, check TT01+TT02 and submit the query should return every single User who has not participated in the following Tests:
A01 - TT01
A01 - TT02
So at last i get a list of users that i could use for the test A01 - TT01+TT03, since there are no conflicts.
So the query would return every user who has not participated in T1, since that is the only conflict.
So the userlist would look like:
U2
U3
U5
Can someone help me with this? Noone got an idea? :'(
{afterlambda { |df, ttf|.