我收到一个奇怪的错误:
ActiveRecord::StatementInvalid in AdminController#edit_user
NoMethodError: undefined method `empty?' for 663:Fixnum: SELECT privileges.*, ...
In: app/controllers/admin_controller.rb:75:in `edit_user'
以下是相关行:
#line #75 from admin_controller.rb
@privileges = Privilege.find_by_sql( "SELECT privileges.*, vendors.name AS vendor_name FROM privileges LEFT JOIN vendors ON vendors.id = rivileges.vendor_id WHERE user_id = ? ORDER BY vendors.name", @user.id)
我可以通过取出占位符来修复它,但我不想这样做:
@privileges = Privilege.find_by_sql( "SELECT privileges.*, vendors.name AS vendor_name FROM privileges LEFT JOIN vendors ON vendors.id = privileges.vendor_id WHERE b2b_user_id = "+@user.id.to_s+" ORDER BY vendors.name")
在Rails 3中没有弃用find_by_sql,我可以将该查询泵入数据库。
对我来说,奇怪的是没有“空”的号召?在我的admin_controller中。这是Rails的内部调用吗?
请告知。
由于
答案 0 :(得分:0)
Rails 3.1中已弃用此语法。
你应该致电
@privileges = Privilege.find_by_sql ["SELECT privileges.*, vendors.name AS vendor_name FROM privileges LEFT JOIN vendors ON vendors.id = rivileges.vendor_id WHERE user_id = ? ORDER BY vendors.name", @user.id]