我正在尝试为学生创建一个注册,以便能够注册他们可用的部分。但是,当我实际点击创建注册按钮时,我不断收到此错误。当我检查实时外壳时,它说@student == nil 意味着它没有被正确创建?我对如何解决这个问题感到困惑
<!---REGISTRATION CONTROLLER-->
def new
@registration = Registration.new
@student = Student.find(params[:student_id])
@info = Section.for_rank(@student.rank).for_age(@student.age).map{|s| ["Name: #{Event.find_by_id(s.event.id).name},
Ranks: #{ s.max_rank == nil ? "#{Student::RANKS[s.min_rank-1][0]} and up" : "#{Student::RANKS[s.min_rank-1][0]} - #{Student::RANKS[s.max_rank-1][0]}"},
Ages: #{ s.max_age == nil ? "#{s.min_age} and up" : "#{s.min_age} - #{s.max_age}" }", s.id] }
end
def create
@registration = Registration.new(params[:registration])
if @registration.save
redirect_to @registration, :notice => "Successful"
else
render :action => 'new'
end
end
<!----MY REGISTRATION FORM -->
<div class="field">
<%= f.hidden_field :student_id, :value => @registration.student_id %>
<div class = "field">
<%= f.select :section_id, options_for_select(@info)%>
<div class="actions">
<%= f.submit nil, :class => 'btn btn-mini' %></th>
<!--- MY STUDENT SHOW THAT CALLS THE REGISTRATION -->
<%= link_to 'Register ', new_registration_path(:student_id => @student.id), :class => 'btn btn-mini' %>