error in your SQL syntax

hi all,
i am getting the following exception ,can anyone know what is the problem ? or can any one what is SQL syntax for following query to run in ruby on rails ?
i am using
Ruby: 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32]
Rails 2.3.11
gem :1.6.2

Processing ExpertController#view_expert_brief (for 127.0.0.1 at 2012-01-09 11:36:03) [GET]
Parameters: {“slug”=>“stephencovey”}
[4;36;1mExpert Columns (0.s)[ [0;1mSHOW FIELDS FROM experts[
[4;35;1mExpert Load (0.s)[ [SELECT * FROM experts WHERE (experts.approved = 1 AND experts.deleted = 0 AND experts.slug = ‘stephencovey’) LIMIT 1[
[4;36;1mExpertCategory Load (0.s)[ [0;1mSELECT expert_categories.* FROM expert_categories INNER JOIN experts ON experts.expert_id = expert_categories.expert_id INNER JOIN categories ON categories.category_id = expert_categories.category_id WHERE (expert_categories.expert_id=178 and category_approved=1 and category_deleted=0 and approved=1 and deleted=0) [
[4;35;1mExpertCategory Columns (15.6ms)[ [SHOW FIELDS FROM expert_categories[
[4;36;1mCategory Columns (0.s)[ [0;1mSHOW FIELDS FROM categories[
[4;35;1mCategory Load (0.s)[ [SELECT * FROM categories WHERE (categories.category_id = 1) [
[4;36;1mCategory Load (0.s)[ [0;1mSELECT * FROM categories WHERE (categories.category_id = 7) [
[4;35;1mCategory Load (0.s)[ [SELECT * FROM categories WHERE (categories.category_id = 8) [
[4;36;1mCategory Load (15.6ms)[ [0;1mSELECT * FROM categories WHERE (categories.category_id = 18) [
[4;35;1mExpert Load (0.s)[ [SELECT * FROM experts WHERE (experts.approved = 1 AND experts.deleted = 0 AND experts.expert_id = 178) LIMIT 1[
[4;36;1mExpertBio Load (0.s)[ [0;1mSELECT * FROM expert_bio WHERE (expert_bio.expert_id = 178) LIMIT 1[
[4;35;1mExpertBio Columns (0.s)[ [SHOW FIELDS FROM expert_bio[
[4;36;1mEvent Load (15.6ms)[ [0;1mSELECT events.* FROM events INNER JOIN experts ON experts.expert_id = events.expert_id WHERE (events.expert_id= 178 and event_date >= ‘2012-01-09’ and expert_events_approved=1 and expert_events_deleted=0 and experts.approved=1 and experts.deleted=0) ORDER BY event_date ASC LIMIT 5[
[4;35;1mEvent Columns (0.s)[ [SHOW FIELDS FROM events[
[4;36;1mSQL (0.s)[ [0;1mMysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘? and event_date >= ? and expert_events_approved=1 and expert_events_deleted=017’ at line 1: SELECT count(expert_id=? and event_date >= ? and expert_events_approved=1 and expert_events_deleted=01782012-01-09) AS count_expert_id_and_event_date_and_expert_events_approved_1_and_expert_events_deleted_0_178_2012_01_09 FROM events [

The error seems to be in this SQL statement:

SELECT count(expert_id=? and event_date >= ? and expert_events_approved=1 and expert_events_deleted=

01782012-01-09) AS count_expert_id_and_event_date_and_expert_events_approved_1_and_expert_events_deleted_0_178_2012_01_09 FROM events

It complains about the “event_date >= ?” where of course the questionmark is wrong.

It looks like you do somehing on the line of

MyModel.where(“event_date >= ?”, @date_var)
(simplified)

But for some reason the questionmark is not replaced by the actual value.

Could you provide the actual Ruby code that is used to generate this query?