Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6728401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:09:57+00:00 2026-05-26T10:09:57+00:00

Help me StackOveflow, you’re my only hope. I’m getting the following error, and its

  • 0

Help me StackOveflow, you’re my only hope.

I’m getting the following error, and its driving me crazy.

NoMethodError in Players#new

Showing /home/paul/rails_projects/recruits/app/views/players/_form.html.haml where line #1 raised:

undefined method `model_name’ for nil:NilClass

Extracted source (around line #1):

1: = form_for @player do |f|

2: -if @player.errors.any?

3: #error_explanation

4: %h2= “#{pluralize(@player.errors.count, “error”)} prohibited this player from being saved:”

Trace of template inclusion: app/views/players/new.html.haml

Rails.root: /home/paul/rails_projects/recruits
Application Trace | Framework Trace | Full Trace

app/views/players/_form.html.haml:1:in _app_views_players__form_html_haml___279577567_106102840'
app/views/players/new.html.haml:3:in
_app_views_players_new_html_haml__860668925_106567710′
app/controllers/players_controller.rb:29:in `new’

I created this using the scaffold generator, which worked fine for me in another area, but not here apparently.

Here are the relevant files (the only change I’ve made to the files generated by the scaffold command was to add attr_accessable to the player model).

models/player.rb

class Player < ActiveRecord::Base 

  attr_accessible :first_name, :last_name, :scout_height, :scout_weight,
  :scout_profile_url, :scout_star_rating, :scout_overall_ranking,
  :scout_position_ranking, :scout_position, :espn_height, :espn_weight,
  :espn_profile_url, :espn_star_rating, :espn_overall_ranking,
  :espn_position_ranking, :espn_position, :rivals_height, :rivals_weight,
  :rivals_profile_url, :rivals_star_rating, :rivals_overall_ranking,
  :rivals_position_ranking, :rivals_position, :maxprep_height, :maxprep_weight,
  :maxprep_profile_url, :maxprep_star_rating, :maxprep_overall_ranking,
  :maxprep_position_ranking, :maxprep_position, :class, :school_commit, :loi_signed

end

controllers/players_controller.rb

class PlayersController < ApplicationController
  # GET /players
  # GET /players.json
  def index
    @players = Player.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @players }
    end
  end

  # GET /players/1
  # GET /players/1.json
  def show
    @player = Player.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @player }
    end
  end

  # GET /players/new
  # GET /players/new.json
  def new
    @player = Player.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @player }
    end
  end

  # GET /players/1/edit
  def edit
    @player = Player.find(params[:id])
  end

  # POST /players
  # POST /players.json
  def create
    @player = Player.new(params[:player])

    respond_to do |format|
      if @player.save
        format.html { redirect_to @player, notice: 'Player was successfully created.' }
        format.json { render json: @player, status: :created, location: @player }
      else
        format.html { render action: "new" }
        format.json { render json: @player.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /players/1
  # PUT /players/1.json
  def update
    @player = Player.find(params[:id])

    respond_to do |format|
      if @player.update_attributes(params[:player])
        format.html { redirect_to @player, notice: 'Player was successfully updated.' }
        format.json { head :ok }
      else
        format.html { render action: "edit" }
        format.json { render json: @player.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /players/1
  # DELETE /players/1.json
  def destroy
    @player = Player.find(params[:id])
    @player.destroy

    respond_to do |format|
      format.html { redirect_to players_url }
      format.json { head :ok }
    end
  end
end

views/players/new.html.haml

%h1 New player

= render 'form'

= link_to 'Back', players_path

views/players/_form.html.haml

= form_for @player do |f|
  -if @player.errors.any?
    #error_explanation
      %h2= "#{pluralize(@player.errors.count, "error")} prohibited this player from being saved:"
      %ul
        - @player.errors.full_messages.each do |msg|
          %li= msg

  .field
    = f.label :first_name
    = f.text_field :first_name
  .field
    = f.label :last_name
    = f.text_field :last_name
  .field
    = f.label :scout_height
    = f.number_field :scout_height
  .field
    = f.label :scout_weight
    = f.number_field :scout_weight
  .field
    = f.label :scout_profile_url
    = f.text_field :scout_profile_url
  .field
    = f.label :scout_star_rating
    = f.number_field :scout_star_rating
  .field
    = f.label :scout_overall_ranking
    = f.number_field :scout_overall_ranking
  .field
    = f.label :scout_position_ranking
    = f.number_field :scout_position_ranking
  .field
    = f.label :scout_position
    = f.text_field :scout_position
  .field
    = f.label :espn_height
    = f.number_field :espn_height
  .field
    = f.label :espn_weight
    = f.number_field :espn_weight
  .field
    = f.label :espn_profile_url
    = f.text_field :espn_profile_url
  .field
    = f.label :espn_star_rating
    = f.number_field :espn_star_rating
  .field
    = f.label :espn_overall_ranking
    = f.number_field :espn_overall_ranking
  .field
    = f.label :espn_position_ranking
    = f.number_field :espn_position_ranking
  .field
    = f.label :espn_position
    = f.text_field :espn_position
  .field
    = f.label :rivals_height
    = f.number_field :rivals_height
  .field
    = f.label :rivals_weight
    = f.number_field :rivals_weight
  .field
    = f.label :rivals_profile_url
    = f.text_field :rivals_profile_url
  .field
    = f.label :rivals_star_rating
    = f.number_field :rivals_star_rating
  .field
    = f.label :rivals_overall_ranking
    = f.number_field :rivals_overall_ranking
  .field
    = f.label :rivals_position_ranking
    = f.number_field :rivals_position_ranking
  .field
    = f.label :rivals_position
    = f.text_field :rivals_position
  .field
    = f.label :maxprep_height
    = f.number_field :maxprep_height
  .field
    = f.label :maxprep_weight
    = f.number_field :maxprep_weight
  .field
    = f.label :maxprep_profile_url
    = f.text_field :maxprep_profile_url
  .field
    = f.label :maxprep_star_rating
    = f.number_field :maxprep_star_rating
  .field
    = f.label :maxprep_overall_ranking
    = f.number_field :maxprep_overall_ranking
  .field
    = f.label :maxprep_position_ranking
    = f.number_field :maxprep_position_ranking
  .field
    = f.label :maxprep_position
    = f.text_field :maxprep_position
  .field
    = f.label :class
    = f.number_field :class
  .field
    = f.label :school_commit
    = f.text_field :school_commit
  .field
    = f.label :loi_signed
    = f.check_box :loi_signed
  .actions
    = f.submit 'Save'

routes.rb

Recruits::Application.routes.draw do

  resources :schools
  resources :players

  #get \"users\/show\"

  root :to => "home#index"

  devise_for :users
  resources :users, :only => :show
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:09:57+00:00Added an answer on May 26, 2026 at 10:09 am

    I’m guessing here but I believe it’s because you gave your Player model an attribute called “class” you should change that to :player_class or something. class is a reserved word. You should also update your _form.html.erb and index.html.erb and show.html.erb files to use this new name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With the help of people on stackoverflow I was able to get the following
Hey guys.I'm new to android and with the help of stackoverflow I somehow managed
I am newbie in C and new to stackoveflow too. I have some problems
With some kindly help from StackOverflow, I've got Unity Framework to create my chained
Now that I have decided upon Firebird , with the help of StackOverflow :),
Help me, Stackoverflow! I have a simple .NET 3.5 console app that reads some
Dear Friends from Stackoverflow, Please help me with a problem that i'm having when
Is there any opensource samples of JQuery usages of StackOverFlow-like sites...... Any help in
First, thanks for all the help I've received so far from StackOverflow. I've learned
Help! I have an Axis web service that is being consumed by a C#

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.