Answer the question
In order to leave comments, you need to log in
How to send a query to the database using the id of the current user with the Devise gem?
Can't get id via current_user (tried current_user.id and current_user.id.to_i). There may be an error in the database query. But the request through "rails c" should be passed with setting the user's id variable instead.
If it doesn't work, another solution to the request, maybe someone knows?
i'm new to Rails (
class MessagesController < ApplicationController
def index
if current_user
user = current_user
@messages = Message.where("user_id = user or recipient_id = user")
else
redirect_to new_user_session_path, notice: 'You are not logged in.'
end
end
end
PG::UndefinedFunction: ERROR: operator does not exist: integer = name
LINE 1: ...ELECT "messages".* FROM "messages" WHERE (user_id = user or ...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT "messages".* FROM "messages" WHERE (user_id = user or recipient_id = user)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question