Forms Rails 3.1脚手架未定义方法`模型名称';零级:零级
帮帮我,你是我唯一的希望 我犯了以下错误,这让我发疯 球员中的诺默德罗#新 显示/home/paul/rails_projects/recrupt/app/views/players/_form.html.haml,其中第1行出现: nil:NilClass的未定义方法“model_name” 提取的源(第1行附近): 1:=形式u表示@player do | f| 2:-如果@player.errors.any 3:#错误#解释 4:%h2=“#{pluralize(@player.errors.count,“error”)}禁止保存此播放器: 模板包含跟踪:app/views/players/new.html.hamlForms Rails 3.1脚手架未定义方法`模型名称';零级:零级,forms,ruby-on-rails-3.1,scaffold,nomethoderror,Forms,Ruby On Rails 3.1,Scaffold,Nomethoderror,帮帮我,你是我唯一的希望 我犯了以下错误,这让我发疯 球员中的诺默德罗#新 显示/home/paul/rails_projects/recrupt/app/views/players/_form.html.haml,其中第1行出现: nil:NilClass的未定义方法“model_name” 提取的源(第1行附近): 1:=形式u表示@player do | f| 2:-如果@player.errors.any 3:#错误#解释 4:%h2=“#{pluralize(@player.error
%h1 New player
= render 'form'
= link_to 'Back', players_path
= 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'
Rails.root:/home/paul/Rails\u项目/招募
应用程序跟踪|框架跟踪|完整跟踪
app/views/players/\u form.html.haml:1:in\u app\u views\u players\u form\u html\u haml\u\u 279577567\u 106102840'
app/views/players/new.html.haml:3:in
\u app\u views\u players\u new\u html\u haml\u 860668925\u 106567710'
app/controllers/players\u controller.rb:29:in'new'
我使用脚手架生成器创建了这个,它在另一个领域对我来说很好,但在这里显然不行
以下是相关文件(我对scaffold命令生成的文件所做的唯一更改是将attr_可访问添加到播放器模型)
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
views/players/_form.html.haml
%h1 New player
= render 'form'
= link_to 'Back', players_path
= 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
我在这里猜测,但我相信这是因为你给了你的玩家模型一个叫做“类”的属性,你应该把它改为:Player_class或者别的什么。类是一个保留字。您还应该更新_form.html.erb和index.html.erb以及show.html.erb文件,以使用此新名称。谢谢David,我已更改了播放器型号命名。我已经做了一些其他的事情来解决这个问题,但回头看,这似乎是可行的,所以我很确定这是由于你的建议,而不是我的其他工作。