语法错误,意外的tCONSTANT

0 ruby ruby-on-rails ruby-on-rails-3

谁能解释一下我的问题是什么:

ActiveRecord::Base.connection.select_values('SELECT c.value FROM custom_values c,
time_entries p, custom_fields cf  where  c.customized_type = 'TimeEntry' 
and p.id = c.customized_id and c.custom_field_id = cf.id 
and cf.type = 'TimeEntryCustomField' and cf.name = 'Reference TS Client' 
and p.id = '+ log.user.id.to_s +' ;')
Run Code Online (Sandbox Code Playgroud)

我只是为"c.customized_type"得到了这个错误.可能是什么问题?

San*_*o J 5

你用'和分号关闭字符串,试试这个:

ActiveRecord::Base.connection.select_values("SELECT c.value FROM custom_values c,
time_entries p, custom_fields cf  where  c.customized_type = 'TimeEntry' 
and p.id = c.customized_id and c.custom_field_id = cf.id 
and cf.type = 'TimeEntryCustomField' and cf.name = 'Reference TS Client' 
and p.id = ?", log.user.id.to_s)
Run Code Online (Sandbox Code Playgroud)