ruby-on-railssession-cookiesruby-on-rails-6impressionsimpressionist

undefined method `cookie_value' for .... Impressionist gem


I've set up the impressionist gem in my Film model. It has been working fine, updating the impressions count, but suddenly I've been receiving the following error when trying to GET the Films#Show page.

undefined method `cookie_value' for "60cb104e4befe185a8b81aac9a2c5e3c":String

It seems like it has something to do with the session_hash, but not sure how to solve this issue.

Does anyone have any ideas?

Here is my Film model:

    class Film < ApplicationRecord


  acts_as_votable
  is_impressionable

  mount_uploader :cover, ImageUploader
  mount_uploader :video, VideoUploader
  mount_uploader :trailer, VideoUploader



   def score
    self.get_upvotes.size - self.get_downvotes.size
  end

  extend FriendlyId
  friendly_id :title, use: :slugged

  # one film has many reviews
  has_many :reviews, dependent: :destroy

  validates :title, presence: true
  validates :author, presence: true
  validates :cover, presence: true
  validates :description, presence: true

end

Films show page

<%= render "shared/ticker" %>




<div class="back-to-films">
  <%= link_to films_path do %>
  <span><%= image_tag "BackArrow1.svg" %> </span><h3 class="back-to-gallery">Back to film gallery</h3>
  <% end %>
</div>



<section class="film-show-grid">

    <div class="film-show-img" onclick="toggle();">
  <%= image_tag @film.cover.show.url %>
  </div>

  <div class="film-show-info">
    <span><% if @film.is_top_pick %>
     <%= image_tag "is_featured.svg", :class => "top-pick-show" %>
   <% end %></span>

  <span class="liking-target">
       <%= link_to like_film_path(@film), class: "upvoted {liked_or_not}", method: :put, remote: :true do %>
       <%= image_tag "Polygon2.svg", :class => "polygon" %>
        <% end %>
        <span class="like_count">
          <%= @film.get_likes.size %>
        </span>
  </span>

    <span class="views">
    <%= image_tag "view.svg", :class => "eyeball" %>
    <span class="impressions"><%= @film.impressionist_count(:filter=>:ip_address) %></span>
    </span>




    <div class="">
      <h2 class="film-title"><%= @film.title %></h2>
      <h6 class="film-author"><%= @film.author %></h6> <span><%= @film.description %></span>
      <p class="film-description"><%= @film.description_body %></p>
    </div>
    <div class="play-button" onclick="toggle();">
      <span> Play </span> <%= image_tag "play.svg", :class => "play-symbol" %>
    </div>
    <div class="preview-button" onclick="toggleTrailer();">
      Trailer
    </div>
    <%= link_to film_reviews_path(@film) do %>
    <div class="cafe-talk-button">
      Café talk
    </div>
    <% end %>

And my full stack trace

impressionist (2.0.0) app/controllers/impressionist_controller.rb:143:in `session_hash'
impressionist (2.0.0) app/controllers/impressionist_controller.rb:60:in `associative_create_statement'
impressionist (2.0.0) app/controllers/impressionist_controller.rb:27:in `impressionist'
app/controllers/films_controller.rb:28:in `show'
actionpack (6.0.3.2) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (6.0.3.2) lib/abstract_controller/base.rb:195:in `process_action'
actionpack (6.0.3.2) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (6.0.3.2) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
activesupport (6.0.3.2) lib/active_support/callbacks.rb:135:in `run_callbacks'
actionpack (6.0.3.2) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (6.0.3.2) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (6.0.3.2) lib/action_controller/metal/instrumentation.rb:33:in `block in process_action'
activesupport (6.0.3.2) lib/active_support/notifications.rb:180:in `block in instrument'
activesupport (6.0.3.2) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
activesupport (6.0.3.2) lib/active_support/notifications.rb:180:in `instrument'
actionpack (6.0.3.2) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (6.0.3.2) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (6.0.3.2) lib/active_record/railties/controller_runtime.rb:27:in `process_action'
actionpack (6.0.3.2) lib/abstract_controller/base.rb:136:in `process'
actionview (6.0.3.2) lib/action_view/rendering.rb:39:in `process'
actionpack (6.0.3.2) lib/action_controller/metal.rb:190:in `dispatch'
actionpack (6.0.3.2) lib/action_controller/metal.rb:254:in `dispatch'
actionpack (6.0.3.2) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
actionpack (6.0.3.2) lib/action_dispatch/routing/route_set.rb:33:in `serve'
actionpack (6.0.3.2) lib/action_dispatch/journey/router.rb:49:in `block in serve'
actionpack (6.0.3.2) lib/action_dispatch/journey/router.rb:32:in `each'
actionpack (6.0.3.2) lib/action_dispatch/journey/router.rb:32:in `serve'
actionpack (6.0.3.2) lib/action_dispatch/routing/route_set.rb:834:in `call'
warden (1.2.8) lib/warden/manager.rb:36:in `block in call'
warden (1.2.8) lib/warden/manager.rb:34:in `catch'
warden (1.2.8) lib/warden/manager.rb:34:in `call'
rack (2.2.3) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.2.3) lib/rack/etag.rb:27:in `call'
rack (2.2.3) lib/rack/conditional_get.rb:27:in `call'
rack (2.2.3) lib/rack/head.rb:12:in `call'
actionpack (6.0.3.2) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
rack (2.2.3) lib/rack/session/abstract/id.rb:266:in `context'
rack (2.2.3) lib/rack/session/abstract/id.rb:260:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/cookies.rb:648:in `call'
activerecord (6.0.3.2) lib/active_record/migration.rb:567:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
activesupport (6.0.3.2) lib/active_support/callbacks.rb:101:in `run_callbacks'
actionpack (6.0.3.2) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/debug_exceptions.rb:32:in `call'
web-console (4.0.4) lib/web_console/middleware.rb:132:in `call_app'
web-console (4.0.4) lib/web_console/middleware.rb:28:in `block in call'
web-console (4.0.4) lib/web_console/middleware.rb:17:in `catch'
web-console (4.0.4) lib/web_console/middleware.rb:17:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (6.0.3.2) lib/rails/rack/logger.rb:37:in `call_app'
railties (6.0.3.2) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (6.0.3.2) lib/active_support/tagged_logging.rb:80:in `block in tagged'
activesupport (6.0.3.2) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (6.0.3.2) lib/active_support/tagged_logging.rb:80:in `tagged'
railties (6.0.3.2) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.2.3) lib/rack/method_override.rb:24:in `call'
rack (2.2.3) lib/rack/runtime.rb:22:in `call'
activesupport (6.0.3.2) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/static.rb:126:in `call'
rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
actionpack (6.0.3.2) lib/action_dispatch/middleware/host_authorization.rb:82:in `call'
webpacker (4.2.2) lib/webpacker/dev_server_proxy.rb:23:in `perform_request'
rack-proxy (0.6.5) lib/rack/proxy.rb:57:in `call'
railties (6.0.3.2) lib/rails/engine.rb:527:in `call'
puma (4.3.5) lib/puma/configuration.rb:228:in `call'
puma (4.3.5) lib/puma/server.rb:713:in `handle_request'
puma (4.3.5) lib/puma/server.rb:472:in `process_client'
puma (4.3.5) lib/puma/server.rb:328:in `block in run'
puma (4.3.5) lib/puma/thread_pool.rb:134:in `block in spawn_thread'

Solution

  • I updated a legacy Rails application that is using the impression gem to version 6 and ran into the same exception. I worked around it by specifying a specific commit for the impression gem in the Gemfile:

    gem 'impressionist',
      git: 'git@github.com:charlotte-ruby/impressionist.git',
      ref: '46a582ff8cd3496da64f174b30b91f9d97e86643'
    
    

    The reason for this is that the fix for the exception is not in their latest release (2.0.0) but is in its master branch.