I have a problem when attempting to populate my sqlite db. There's not much info regarding the specific error "finder_needs_type_condition?" that I can find, but I don't have much experience with Rails yet to even suspect where the problem could be.
Model:
class Character < ActiveRecord::Base
validates :user_id, :name, :class, presence: true
end
Controller:
class CharactersController < ApplicationController
before_action :authenticate_user!
respond_to :json
@user_id = current_user[:id]
def index
@characters = Character.all
end
def show
@character = Character.find(params[:id])
end
def new
@character = Character.new
end
def create
@characters = Character.all
@character = Character.create(character_params)
end
private
def character_params
params.require(:character).permit(:user_id, :name, :class)
end
end
schema.rb:
create_table "characters", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name"
t.string "class"
t.integer "user_id", default: 0, null: false
end
seeds.rb:
Character.delete_all
Character.create!([
{id: 1, name: "nameone", class: "Warrior", user_id: 1},
{id: 2, name: "nametwo", class: "Mage", user_id: 1},
{id: 3, name: "namethree", class: "Wizard", user_id: 1},
{id: 4, name: "namefour", class: "Warlock", user_id: 1},
{id: 5, name: "namefive", class: "Rogue", user_id: 1}
])
And the error when attempting seed:
$ bundle exec rake db:seed
rake aborted!
NoMethodError: undefined method `finder_needs_type_condition?' for nil:NilClass
/var/rubyapps/test/db/seeds.rb:2:in `<top (required)>'
Tasks: TOP => db:seed
Have I misunderstood something when generating the model?
let(:character1) { Character.create(user: user, name: "characterName", class: "Wizard") }}
– Neils