NoMethodError (undefined method `sismember' for nil:NilClass)…Trying to deploy on heroku

I get the following error:

2015-05-17T17:25:40.349230+00:00 app[web.1]: Started GET "/movies/1" for 160.9.0.153 at 2015-05-17 17:25:40 +0000 2015-05-17T17:25:40.423697+00:00 app[web.1]: Completed 500 Internal Server Error in 67ms 2015-05-17T17:25:40.355931+00:00 app[web.1]: Processing by MoviesController#show as HTML 2015-05-17T17:25:40.425095+00:00 app[web.1]: 2015-05-17T17:25:40.406984+00:00 app[web.1]: Movie Load (2.4ms) SELECT "movies".* FROM "movies" WHERE "movies"."id" = $1 LIMIT 1 [["id", 1]] 2015-05-17T17:25:40.425098+00:00 app[web.1]: NoMethodError (undefined method `sismember' for nil:NilClass): 2015-05-17T17:25:40.425100+00:00 app[web.1]: app/models/movie.rb:20:in `cart_action' 2015-05-17T17:25:40.425102+00:00 app[web.1]: 2015-05-17T17:25:40.425101+00:00 app[web.1]: app/controllers/movies_controller.rb:9:in `show' 2015-05-17T17:25:40.425104+00:00 app[web.1]: 2015-05-17T17:25:41.951208+00:00 heroku[router]: at=info method=GET path="/movies/4" host=hidden-savannah-5835.herokuapp.com request_id=cbb36b63-06ee-4da0-992d-6d512d431ea4 fwd="160.9.0.153" dyno=web.1 connect=0ms service=17ms status=500 bytes=1714 2015-05-17T17:25:41.932183+00:00 app[web.1]: Started GET "/movies/4" for 160.9.0.153 at 2015-05-17 17:25:41 +0000 2015-05-17T17:25:41.941428+00:00 app[web.1]: Completed 500 Internal Server Error in 5ms 2015-05-17T17:25:41.935883+00:00 app[web.1]: Processing by MoviesController#show as HTML 2015-05-17T17:25:41.935891+00:00 app[web.1]: Parameters: {"id"=>"4"} 2015-05-17T17:25:41.939396+00:00 app[web.1]: Movie Load (2.2ms) SELECT "movies".* FROM "movies" WHERE "movies"."id" = $1 LIMIT 1 [["id", 4]] 2015-05-17T17:25:41.944520+00:00 app[web.1]: 2015-05-17T17:25:41.944523+00:00 app[web.1]: NoMethodError (undefined method `sismember' for nil:NilClass): 2015-05-17T17:25:41.944525+00:00 app[web.1]: app/models/movie.rb:20:in `cart_action' 2015-05-17T17:25:41.944526+00:00 app[web.1]: app/controllers/movies_controller.rb:9:in `show' 2015-05-17T17:25:41.944528+00:00 app[web.1]: 2015-05-17T17:25:41.944529+00:00 app[web.1]:

movie.rb (model)

class Movie < ActiveRecord::Base   has_many :purchases   has_many :buyers, through: :purchases

  before_save :embed_video_url

  def poster     "http://ia.media-imdb.com/images/M/#\{poster\_url\}&quot;   end

  def imdb     "http://www.imdb.com/title/#\{imdb\_id\}/&quot;   end

  def embed_video_url     self.video_url = "//www.youtube.com/embed/#{video_url.split('v=')[1].split('&list')[0]}"   end

  def cart_action(current_user_id)     if $redis.sismember "cart#{current_user_id}", id       "Remove from"     else       "Add to"     end   end end

movies_controller.rb

class MoviesController < ApplicationController

  def index     @movies = Movie.all   end

  def show     @movie = Movie.find(params[:id])     @cart_action = @movie.cart_action current_user.try :id   end

end

The weird about this error is that the application run without any problem locally but when I deployed to heroku I can see the first page but when I click to a movie or trying to log in i get error.

Any help?

You did not include the code that sets $redis, and I suspect that’s where the problem is. Connecting to Redis on Heroku may be slightly different that local, since dynos are not guaranteed to continue existing between requests.

–Matt Jones