Ruby on rails 无法将表单数据保存到rails中的数据库中

Ruby on rails 无法将表单数据保存到rails中的数据库中,ruby-on-rails,ruby-on-rails-5,Ruby On Rails,Ruby On Rails 5,我已经创建了一个scaffold name项目,并创建了另一个scaffold name项目 阶段项目和阶段之间存在一对多的关联。就像每个项目都有多个阶段。我能够呈现后台表单,但无法将数据保存到数据库的后台表中。 stage form.html.erb <%= form_with(model: stage, url: [@project, stage], local: true) do |form| %> <% if @stage.errors.any? %>

我已经创建了一个scaffold name项目,并创建了另一个scaffold name项目 阶段项目和阶段之间存在一对多的关联。就像每个项目都有多个阶段。我能够呈现后台表单,但无法将数据保存到数据库的后台表中。

stage form.html.erb

<%= form_with(model: stage, url: [@project, stage], local: true) do |form| %>
  <% if @stage.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(stage.errors.count, "error") %> prohibited this stage from being saved:</h2>

      <ul>
      <% stage.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

<div class="row select-date-wrapper">
  <div class="field columns large-6">
    <%= form.label :stage %>
    <%= form.text_field :stage %>
  </div>

  <div class="field columns large-3">
    <%= form.label :planned_start_date %>
    <%= form.date_select :planned_start_date, class: 'select-date' %>
  </div>
  <div class="actions">
    <%= form.submit 'Create', :class=>"button primary small" %>
  </div>
<% end %>
模型项目.rb

has_many :stages
model stage.rb

  #belongs_to :project
  has_many :tasks
routes.rb

  resources :projects do
    resources :stages
  end
你试过这个吗

if @stage.save
  format.html { redirect_to project_stage_path(@project, @stage), notice: 'Stage was successfully created.' }
  format.json { render :show, status: :created, location: @stage }
else
  format.html { render :new }
  format.json { render json: @stage.errors, status: :unprocessable_entity }
end

请将
url:[@project,stage]
更改为
url:stages\u path

始终尝试将控制器名称设为复数<代码>阶段\控制器

if @stage.save
  format.html { redirect_to project_stage_path(@project, @stage), notice: 'Stage was successfully created.' }
  format.json { render :show, status: :created, location: @stage }
else
  format.html { render :new }
  format.json { render json: @stage.errors, status: :unprocessable_entity }
end