title: rails 4 many to many though join model, undefined method 'name' for:NilClass, sqlite3
body: <p>Hey guys I have a pretty simple many to many set up between User Movies through WatchList. It's an app that searches the itunes api for movies, here I'm adding the abilty for user to save searched movies to a personal list. I'm using Rails 4.1.1 and sqlite3.  </p>
  
  <pre><code>class User &lt; ActiveRecord::Base
  
    has_secure_password
  
    validates :email, presence: true, uniqueness: true
    validates :name, presence: true
    validates :password, length: { minimum: 6 }, allow_nil: true
  
    has_many :watch_lists
    has_many :movies, through: :watch_lists
  
    def add_movie(movie)
    self.movies &lt;&lt; movie
  end
  
  class Movie &lt; ActiveRecord::Base
    has_many :watch_lists
    has_many :users, through: :watch_lists
  end
  
  class WatchList &lt; ActiveRecord::Base
    belongs_to :user
    belongs_to :movie
  end
  </code></pre>
  
  <p>I problem is when I try and add the movie which uses the itunes id for the DB :id. in the saves_controller on line 7 it throws undefined method 'name' for nil:NilClass. I can't figure it out, nothing is nil? Movie saves to db fine, with proper info. It's when I try and create the join table. What is rails trying to call 'name' on???</p>
  
  <p><strong>line 7 raises error current_user.movies &lt;&lt; @movie => undefined method 'name for nil:NilClass</strong></p>
  
  <pre><code>class SavesController &lt; ApplicationController
  def create
    temp_movie = aquire_movie
    @movie = Movie.new(temp_movie.local_db_movie_info_hash)
  
    if @movie.save
      current_user.movies &lt;&lt; @movie #### =&gt; LINE 7 ERROR undefined methond 'name for nil:NilClass
      redirect_to @movie
    end
  end
  
  private
  
  def aquire_movie
    movie_data = itunes_results[:results][0]
    TemporaryMovie.new(movie_data)
  end
  
  def itunes_results
    data_retriever.get_data(params[:movie_id], search_by_id: true)
  end
  </code></pre>
  
  <p>end</p>
  
  <p>Here is the schema as well.</p>
  
  <pre><code>    ActiveRecord::Schema.define(version: 20150330012300) do
  
    create_table "movies", force: true do |t|
      t.string   "title"
      t.datetime "created_at"
      t.datetime "updated_at"
    end
  
    create_table "users", force: true do |t|
      t.string   "name"
      t.string   "email"
      t.string   "password_digest"
      t.string   "auth_token"
      t.datetime "created_at"
      t.datetime "updated_at"
    end
  
    add_index "users", ["auth_token"], name: "index_users_on_auth_token"
    add_index "users", ["email"], name: "index_users_on_email"
  
    create_table "watch_lists", force: true do |t|
      t.integer  "movie_id"
      t.integer  "user_id"
      t.datetime "created_at"
      t.datetime "updated_at"
    end
  end
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>I just had a friend clone this repo and he had no issues so it's some sort of gem /database issue ??</p>