以下 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'