Robbie:
Try this:
find_by_sql ["SELECT * FROM staffmembertable WHERE print IN (?) ORDER BY
staff_type", @params[''print''] ]
This works for me in a similar setting... also notice that the find_by_sql
is in []
The cool thing is that it works if there is just one item in the print
array. I haven''t done any checking yet to see what happens if the array
is
nothing
There might be a "nicer" way of doing the above... but this should get
you
working.
aw
On 6/15/05, Robbie Shepherd
<robbie.shepherd-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> ok, two posts from me in one day, that can''t be good.
I''ve got one last
> stumbling block before finishing this application, and I can''t get
my head
> around it.
>
> I have a form filled with a list of staff members, and each staff member
> has a staff_type varchar column in the staffmembers table associated with
> it. The form has a series of checkboxes which allow the user to select a
> number of staffmembers. Upon submitting the form, I want to display the
> returned array of staffmembers, ordered by their staff_type.
>
> The form sends an array of staff_id''s called print[] to the action
:print.
> If I do:
> @staffmembers = Staffmember.find(@params[''print''])
>
> it returns a list of staffmembers, ordered by the id number in the
> staffmember table, even if my print[] array looks like 6,2,4,33, it returns
> the rows in the order 2,4,6,33.
>
> I tried doing
> @staffmembers = Staffmember.find(@params[''print''], :order
=> "staff_type
> DESC")
>
> but it doesnt seem to work. I''ve tried untold variations on
find(:all,
> ...) and find_by_sql etc but these only work when you want to return a
> single row, not a series of rows based on an array.
>
> Any clues/help much appreciated!
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails