NoMethodError (undefined method `id' for {"init"=>true}:Hash):
For my setup, I added is_impressionable to my Posts model, and in the PostsController I am testing with a simple method like so:
def mark_as_viewed
impressionist(@post)
end
I can think of a few places where things may have gone wrong to cause the error. The first is that I changed all the id types in the gem's migration to use UUIDs. The result is this:
The second is that when I initially installed the gem I was seeing a different error that said something like
undefined method `cookie_value'
which I got around by installing a specific commit, as suggested in this post.
Here's a stack trace of the issue:
app/controllers/api/posts_controller.rb:10:in `mark_as_viewed'
Started POST "/api/posts/3f278426-3c09-4b9d-b56d-9668ce559ebb/view" for ::1 at 2021-02-18 09:12:40 -0500
(1.4ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
Processing by Api::PostsController#mark_as_viewed as JSON
Parameters: {"id"=>"3f278426-3c09-4b9d-b56d-9668ce559ebb", "post"=>{}}
User Load (0.9ms) SELECT "users".* FROM "users" WHERE "users"."email" = $1 AND "users"."hidden_id" = $2 LIMIT $3 [["email", "testing@example.com"], ["hidden_id", "YJcrbdHDZqeII2vq6TcvdM04zn42"], ["LIMIT", 1]]
↳ app/models/authentication_manager.rb:11:in `current_user'
Post Load (1.0ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = $1 LIMIT $2 [["id", "3f278426-3c09-4b9d-b56d-9668ce559ebb"], ["LIMIT", 1]]
↳ app/controllers/api/posts_controller.rb:83:in `set_post'
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."email" = $1 AND "users"."hidden_id" = $2 LIMIT $3 [["email", "testing@example.com"], ["hidden_id", "YJcrbdHDZqeII2vq6TcvdM04zn42"], ["LIMIT", 1]]
↳ app/models/authentication_manager.rb:11:in `current_user'
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."email" = $1 AND "users"."hidden_id" = $2 LIMIT $3 [["email", "testing@example.com"], ["hidden_id", "YJcrbdHDZqeII2vq6TcvdM04zn42"], ["LIMIT", 1]]
↳ app/models/authentication_manager.rb:11:in `current_user'
Completed 500 Internal Server Error in 78ms (ActiveRecord: 19.9ms | Allocations: 28661)
NoMethodError (undefined method `id' for {"init"=>true}:Hash):
app/controllers/api/posts_controller.rb:10:in `mark_as_viewed'
I have made sure that params[:id] is correct, @post is set correctly, and that current_user is set correctly, so I'm not sure what's causing this issue.
I keep getting this error:
For my setup, I added
is_impressionable
to my Posts model, and in the PostsController I am testing with a simple method like so:I can think of a few places where things may have gone wrong to cause the error. The first is that I changed all the id types in the gem's migration to use UUIDs. The result is this:
The second is that when I initially installed the gem I was seeing a different error that said something like
which I got around by installing a specific commit, as suggested in this post.
Here's a stack trace of the issue:
I have made sure that
params[:id]
is correct,@post
is set correctly, and thatcurrent_user
is set correctly, so I'm not sure what's causing this issue.