Ruby on rails 无法到达下一个表单';RoR 3+';

Ruby on rails 无法到达下一个表单';RoR 3+';,ruby-on-rails,ruby-on-rails-3,forms,Ruby On Rails,Ruby On Rails 3,Forms,我在申请表中做了一个入学部分,应该有3个步骤,第一步是学生详细信息,第二步是监护人详细信息,第三步是学生以前的数据,第1步和第2步成功完成,问题是当我单击“保存并继续”时,我无法进入第三个表单 注:学生和学生之前的数据之间存在关系 学生有一个学生以前的数据,监护人和学生以前的数据之间没有关系 学生表格会将我重定向到监护人表格,监护人表格会将我重定向到学生以前的数据表格,但不会 student.rb class Student < ActiveRecord::Base attr_acce

我在申请表中做了一个入学部分,应该有3个步骤,第一步是学生详细信息,第二步是监护人详细信息,第三步是学生以前的数据,第1步和第2步成功完成,问题是当我单击“保存并继续”时,我无法进入第三个表单

注:学生和学生之前的数据之间存在关系 学生有一个学生以前的数据,监护人和学生以前的数据之间没有关系

学生表格会将我重定向到监护人表格,监护人表格会将我重定向到学生以前的数据表格,但不会

student.rb

class Student < ActiveRecord::Base
  attr_accessible :address_line1, :address_line2, :admission_date, :admission_no, :birth_place, :blood_group, :city,
                  :class_roll_no, :date_of_birth, :email, :first_name, :gender, :language, :last_name, :middle_name,
                  :phone1, :phone2, :post_code, :religion, :country_id, :nationality_id  , :guardians_attributes ,
                  :student_previous_data_attributes

  belongs_to :user
  belongs_to :country
  belongs_to :school
  belongs_to :batch
  belongs_to :nationality , class_name: 'Country'
  has_many :guardians
  has_many :student_previous_subject_marks
  has_one :student_previous_data
  accepts_nested_attributes_for :guardians
  accepts_nested_attributes_for :student_previous_data
end
学生\以前的\数据/new.html.erb

<%= bootstrap_form_for(@student_previous_data, :url => student_student_previous_datum_path(@student),
                           html: { class: 'form-horizontal' }, method: :post) do |f| %>
        <% if @student_previous_data.errors.any? %>
            <div id="error_explanation">
              <div class="alert alert-error">
                The form contains <%= pluralize(@student_previous_data.errors.count, 'error') %>
              </div>
              <ul>
                <% @student_previous_data.errors.full_messages.each do |msg| %>
                    <li>* <%= msg %></li>
                <% end %>
              </ul>
            </div>
        <% end %>

        <fieldset>
          <div class="field">
            <%= f.hidden_field :student_id, value: @student.id %>

          </div>

          <h4>Previous Educational Details</h4>
          <div class="field">
            <%= f.text_field :institution, label: 'Institution Name'%>
          </div>
          <div class="field">
            <%= f.text_field :course, label: 'Course'%>
          </div>
          <div class="field">
            <%= f.text_field :year, label: 'Year'%>
          </div>
          <div class="field">
            <%= f.text_field :total_mark, label: 'Total Mark'%>
          </div>
          <div class="actions"><%= f.submit 'Save & Proceed', class: 'btn btn-mini btn-primary' %></div>
        </fieldset>
    <% end %>
  </div>
</div>
<h1>Admission</h1>
<h4>Step 3 - Previous details</h4>

<div class="row-fluid">
  <div class="span5 offset1 hero-unit">
    <%= bootstrap_form_for(@student_previous_data, :url => student_student_previous_datum_path(@student),
                           html: { class: 'form-horizontal' }) do |f| %>
        <% if @student_previous_data.errors.any? %>
            <div id="error_explanation">
              <div class="alert alert-error">
                The form contains <%= pluralize(@student_previous_data.errors.count, 'error') %>
              </div>
              <ul>
                <% @student_previous_data.errors.full_messages.each do |msg| %>
                    <li>* <%= msg %></li>
                <% end %>
              </ul>
            </div>
        <% end %>

        <fieldset>
          <div class="field">
            <%= f.hidden_field :student_id, value: @student.id %>

          </div>

          <h4>Previous Educational Details</h4>
          <div class="field">
            <%= f.text_field :institution, label: 'Institution Name'%>
          </div>
          <div class="field">
            <%= f.text_field :course, label: 'Course'%>
          </div>
          <div class="field">
            <%= f.text_field :year, label: 'Year'%>
          </div>
          <div class="field">
            <%= f.text_field :total_mark, label: 'Total Mark'%>
          </div>
          <div class="actions"><%= f.submit 'Save & Proceed', class: 'btn btn-mini btn-primary' %></div>
        </fieldset>
    <% end %>
  </div>
</div>
使用Marek Lipka的解决方案后,我得到以下错误(完全错误):

这也是我的学生之前的数据/new.html.erb

<%= bootstrap_form_for(@student_previous_data, :url => student_student_previous_datum_path(@student),
                           html: { class: 'form-horizontal' }, method: :post) do |f| %>
        <% if @student_previous_data.errors.any? %>
            <div id="error_explanation">
              <div class="alert alert-error">
                The form contains <%= pluralize(@student_previous_data.errors.count, 'error') %>
              </div>
              <ul>
                <% @student_previous_data.errors.full_messages.each do |msg| %>
                    <li>* <%= msg %></li>
                <% end %>
              </ul>
            </div>
        <% end %>

        <fieldset>
          <div class="field">
            <%= f.hidden_field :student_id, value: @student.id %>

          </div>

          <h4>Previous Educational Details</h4>
          <div class="field">
            <%= f.text_field :institution, label: 'Institution Name'%>
          </div>
          <div class="field">
            <%= f.text_field :course, label: 'Course'%>
          </div>
          <div class="field">
            <%= f.text_field :year, label: 'Year'%>
          </div>
          <div class="field">
            <%= f.text_field :total_mark, label: 'Total Mark'%>
          </div>
          <div class="actions"><%= f.submit 'Save & Proceed', class: 'btn btn-mini btn-primary' %></div>
        </fieldset>
    <% end %>
  </div>
</div>
<h1>Admission</h1>
<h4>Step 3 - Previous details</h4>

<div class="row-fluid">
  <div class="span5 offset1 hero-unit">
    <%= bootstrap_form_for(@student_previous_data, :url => student_student_previous_datum_path(@student),
                           html: { class: 'form-horizontal' }) do |f| %>
        <% if @student_previous_data.errors.any? %>
            <div id="error_explanation">
              <div class="alert alert-error">
                The form contains <%= pluralize(@student_previous_data.errors.count, 'error') %>
              </div>
              <ul>
                <% @student_previous_data.errors.full_messages.each do |msg| %>
                    <li>* <%= msg %></li>
                <% end %>
              </ul>
            </div>
        <% end %>

        <fieldset>
          <div class="field">
            <%= f.hidden_field :student_id, value: @student.id %>

          </div>

          <h4>Previous Educational Details</h4>
          <div class="field">
            <%= f.text_field :institution, label: 'Institution Name'%>
          </div>
          <div class="field">
            <%= f.text_field :course, label: 'Course'%>
          </div>
          <div class="field">
            <%= f.text_field :year, label: 'Year'%>
          </div>
          <div class="field">
            <%= f.text_field :total_mark, label: 'Total Mark'%>
          </div>
          <div class="actions"><%= f.submit 'Save & Proceed', class: 'btn btn-mini btn-primary' %></div>
        </fieldset>
    <% end %>
  </div>
</div>
入场券
步骤3-以前的详细信息
学生上一个数据路径(@student),
html:{class:'form horizontal'})do | f |%>
表格包含
  • *
以前的教育细节

那么如何解决这个问题呢?

您应该设置
@student
实例变量-发生错误是因为它是
nil
。您可以在过滤器之前的
中执行此操作,例如:

class GuardiansController < ApplicationController
  before_filter :set_student, :only => [:new, :create] # specify in which actions you need this here
  # ...
  private
    def set_student
      @student = Student.find params[:student_id]
    end
  # ..
end
试着改变这个

new_student_student_previous_datum_path(@student) 

如果它仍然抛出错误,请向我粘贴完整的路由错误

更新:

错误出现在当前表单的此url所在的视图中

这一个正在生成错误:操作:“show”

换成

新建学生上一个数据路径(@student)

new_student_student_previous_datum_路径(@student),
html:{class:'form horizontal'},:method=>“post”)do | f |%>

新建和创建操作共享相同的路径,但该操作是通过请求postget

的方法定义的,该错误指向哪个文件/行?app/controllers/guarders\u controller.rb:19:in“create”,在创建操作中,只添加了代码,并按照您所说的操作,而不编辑其他行,我得到了这个错误
路由错误没有路由匹配{:action=>“show”,:controller=>“student_previous_data”,:student_id=>#}
注意:它应该将我重定向到我构建的previous_数据表单是的,这是因为这一行中有另一个错误。现在检查我的更新答案。刚刚添加了
重定向到新的\u学生\u学生\u以前的\u数据\u路径(@student)
,但同样的错误,我缺少什么??:(如何
重定向到控制器:'student\u previous\u data',action:'new',student\u id:@student.id
?相同的错误,我已经用完整的错误更新了我的问题,正如你所说的问题在视图中,当我添加方法post student\u student\u previous\u data\u path(@student),html:{class:'form horizontal'},method::post)是否要| f |%>以确保您的表单中有:url=>new_student_student_previous_datum_path(@student)和开头的新路径?
Routing Error

No route matches {:action=>"show", :controller=>"student_previous_data", :student_id=>#<Student id: 13, admission_no: "587", class_roll_no: nil, admission_date: nil, first_name: "", middle_name: "", last_name: "", date_of_birth: nil, gender: "Male", blood_group: "Unknown", birth_place: "", language: "", religion: nil, address_line1: "", address_line2: "", city: "", post_code: "", phone1: "", phone2: "", email: "", created_at: "2013-06-28 02:12:46", updated_at: "2013-06-28 02:12:46", country_id: nil, user_id: nil, school_id: nil, nationality_id: nil, passport_number: nil, has_paid_fees: nil, enrollment_date: nil, batch_id: nil>}

Try running rake routes for more information on available routes. 
new_student_student_previous_datum GET    /students/:student_id/student_previous_data/new(.:format)      student_previous_data#new
<h1>Admission</h1>
<h4>Step 3 - Previous details</h4>

<div class="row-fluid">
  <div class="span5 offset1 hero-unit">
    <%= bootstrap_form_for(@student_previous_data, :url => student_student_previous_datum_path(@student),
                           html: { class: 'form-horizontal' }) do |f| %>
        <% if @student_previous_data.errors.any? %>
            <div id="error_explanation">
              <div class="alert alert-error">
                The form contains <%= pluralize(@student_previous_data.errors.count, 'error') %>
              </div>
              <ul>
                <% @student_previous_data.errors.full_messages.each do |msg| %>
                    <li>* <%= msg %></li>
                <% end %>
              </ul>
            </div>
        <% end %>

        <fieldset>
          <div class="field">
            <%= f.hidden_field :student_id, value: @student.id %>

          </div>

          <h4>Previous Educational Details</h4>
          <div class="field">
            <%= f.text_field :institution, label: 'Institution Name'%>
          </div>
          <div class="field">
            <%= f.text_field :course, label: 'Course'%>
          </div>
          <div class="field">
            <%= f.text_field :year, label: 'Year'%>
          </div>
          <div class="field">
            <%= f.text_field :total_mark, label: 'Total Mark'%>
          </div>
          <div class="actions"><%= f.submit 'Save & Proceed', class: 'btn btn-mini btn-primary' %></div>
        </fieldset>
    <% end %>
  </div>
</div>
class GuardiansController < ApplicationController
  before_filter :set_student, :only => [:new, :create] # specify in which actions you need this here
  # ...
  private
    def set_student
      @student = Student.find params[:student_id]
    end
  # ..
end
redirect_to controller: 'student_previous_data', action:'new', student_id: @student.id
new_student_student_previous_datum_path(@student) 
new_student_student_previous_datum_path(student_id: @student.id)
<%= bootstrap_form_for(@student_previous_data, :url => new_student_student_previous_datum_path(@student),
                       html: { class: 'form-horizontal' }, :method => "post") do |f| %>