Rails 2到Rails 3 - ActiveRecord :: StatementInvalid

时间:2013-03-12 12:32:29

标签: ruby-on-rails-3 activerecord

以下ActiveRecord调用会导致InvalidStatement错误。当我甚至提供硬编码的用户ID时会发生这种情况。会话转储显示会话变量“user_id”,该变量也具有有效值。有人可以帮忙吗?

def index
 @nav = []
 @user = B2bUser.find(request.session[:user_id])
 @privileges = B2bPrivilege.lookup_all request.session[:user_id]
end

## lookup_all method from b2b_privilege model
def B2bPrivilege.lookup_all current_user_id
  return B2bPrivilege.find_by_sql("SELECT b2b_privileges.*, vendors.name AS vendor_name FROM b2b_privileges LEFT JOIN vendors ON vendors.id = b2b_privileges.vendor_id WHERE b2b_user_id = ?", current_user_id)
end

Processing by HomeController#index as HTML
Could not log "sql.active_record" event. NoMethodError: undefined method `name' for nil:NilClass
PG::Error: ERROR:  zero-length delimited identifier at or near """"
LINE 1: ..."b2b_users".* FROM "b2b_users"  WHERE "b2b_users"."" = $1 LI...
                                                         ^
: SELECT  "b2b_users".* FROM "b2b_users"  WHERE "b2b_users"."" = $1 LIMIT 1
Completed 500 Internal Server Error in 13ms

ActiveRecord::StatementInvalid (PG::Error: ERROR:  zero-length delimited identifier at or near """"
LINE 1: ..."b2b_users".* FROM "b2b_users"  WHERE "b2b_users"."" = $1 LI...
                                                         ^
: SELECT  "b2b_users".* FROM "b2b_users"  WHERE "b2b_users"."" = $1 LIMIT 1):
app/controllers/home_controller.rb:7:in `index'

0 个答案:

没有答案