次の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'