Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 表单未保存到数据库_Ruby On Rails_Ruby On Rails 3_Forms_Datepicker - Fatal编程技术网

Ruby on rails 表单未保存到数据库

Ruby on rails 表单未保存到数据库,ruby-on-rails,ruby-on-rails-3,forms,datepicker,Ruby On Rails,Ruby On Rails 3,Forms,Datepicker,我正在尝试保存插入表单的数据,当我按下save&Procedure时,它会再次转到“new”(新建),我尝试更改控制器中的错误操作并将其重定向到应用程序的任何页面,但它根本不会响应错误操作,浏览器中的url会更改为: 0.0.0.0:3000/students/15/student_previous_data/new?utf8=%E2%9C%93&student_previous_data[student_id]=15&student_previous_data[institut

我正在尝试保存插入表单的数据,当我按下save&Procedure时,它会再次转到“new”(新建),我尝试更改控制器中的错误操作并将其重定向到应用程序的任何页面,但它根本不会响应错误操作,浏览器中的url会更改为:

0.0.0.0:3000/students/15/student_previous_data/new?utf8=%E2%9C%93&student_previous_data[student_id]=15&student_previous_data[institution]=institution&student_previous_data[course]=course&student_previous_data[year]=2010&student_previous_data[total_mark]=60&commit=Save+%26+Proceed
对于year属性,我使用bootstrap datepicker,并使用以下JQuery代码

jQuery ->
  $(".year").datepicker( { format: "yyyy", viewMode: "years", minViewMode: "years", autoclose: true });
这就是我的控制器中的创建操作

  def create
    @student_previous_data = StudentPreviousData.new(params[:student_previous_data])
    if @student_previous_data.save
      flash[:success] = 'Record Saved Successfully.'
      redirect_to '/user/dashboard'
    else
      flash.now[:error] = 'An error occurred please try again!'
      render 'new'
    end
  end
学生\以前的\数据/new.html.erb

<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 => new_student_student_previous_datum_path(@student),
                           html: { class: 'form-horizontal' }, method: :get) 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 , class: '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>

如何使表单变为true以保存在数据库中?

您的表单url不正确。您的url应如下所示:

:url => student_student_previous_data_path(@student)
您当前的url

:url => new_student_student_previous_datum_path(@student)

始终会直接将您重定向到新操作。您将永远无法通过创建操作。

您的表单url不正确。您的url应如下所示:

:url => student_student_previous_data_path(@student)
您当前的url

:url => new_student_student_previous_datum_path(@student)

始终会直接将您重定向到新操作。您将永远无法通过创建操作。

您使用的是
GET
方法,使用
POST
方法


并在url中使用
student\u student\u previous\u data\u path(@student)
您使用的是
GET
方法,使用
POST
方法


并使用url中的
student\u student\u先前的数据路径(@student)
将您的表单更改为

<%= bootstrap_form_for(@student_previous_data, :url => student_student_previous_data_path(@student),
                       html: { class: 'form-horizontal' }, method: :post) do |f| %>
student\u student\u上一个数据路径(@student),
html:{class:'form horizontal'},method::post)do | f |%>

new_student_student_previous_datum_路径(@student),
html:{class:'form horizontal'},方法::get)do | f |%>

它会起作用。

将您的表单更改为

<%= bootstrap_form_for(@student_previous_data, :url => student_student_previous_data_path(@student),
                       html: { class: 'form-horizontal' }, method: :post) do |f| %>
student\u student\u上一个数据路径(@student),
html:{class:'form horizontal'},method::post)do | f |%>

new_student_student_previous_datum_路径(@student),
html:{class:'form horizontal'},方法::get)do | f |%>


它会起作用。

这是名称本身的问题,控制器应接受名称为
单数
,但表单接受名称为
复数
,我已经创建了一个新的
控制器
模型
,名为
'previous\u detail'
,在控制器中它应该是>>
重定向到新的学生上一个细节路径(@student)
,格式应该是
学生上一个细节路径(@student)
名称本身就是一个问题,控制器应接受名称为
单数
,但表单接受名称为
复数
,我已创建了一个新的
控制器
模型
,名称为
'previous\u detail'
,在控制器中,它应为>
重定向到new\u student\u previous\u detail\u路径(@student)
表单中应该是
student\u previous\u details\u path(@student)

保存/继续逻辑的查看代码是什么样子?问题已更新,我添加了new.html.erb您的url错误。运行rake routes并找到正确的RouterMake routes添加到问题中,我应该做什么?从Rails向导开始。看起来您不知道自己在做什么。保存/继续逻辑的视图代码是什么样子的?问题更新后,我添加了new.html.erbyour url错误。运行rake routes并找到正确的RouterMake routes添加到问题中,我应该做什么?从Rails向导开始。看起来你不知道你在做什么。我以前试过,现在又试过,以确保它不起作用,因为它在重定向到新表单之前引发了一个错误,这是我以前的错误,如果我使用你的解决方案,它将再次发生。你还有
方法::get
。你需要POST.dude,我已经试过了,但是它引发了路由错误,没有路由匹配{:action=>“show”,:controller=>“student\u previous\u data”,:student_id=>#我以前试过,现在又试过,以确保它不起作用,因为它在重定向到新表单之前引发了一个错误,这是我以前的错误,如果我使用您的解决方案,它将再次发生。您也有
方法::get
。您需要发布。伙计,我试过,但它会引发路由错误No-route匹配{:action=>“show”,:controller=>“student_previous_data”,:student_id=>#不工作会引发路由错误没有路由匹配{:action=>“show”,:controller=>“student_previous_data”,:student_id=>#它不应该访问POST方法的显示操作。请粘贴
routes.rb
文件好吗?不使用它会引发路由错误没有与之匹配的路由{:action=>“show”,:controller=>“student_previous_data”,:student_id=>#它不应该访问POST方法的show action。请粘贴
routes.rb
文件好吗?