Ruby on rails 表单字段未保存到数据库中-ruby on rails

Ruby on rails 表单字段未保存到数据库中-ruby on rails,ruby-on-rails,form-submit,Ruby On Rails,Form Submit,我这里有一张表格 在routes.rb中,我有 在你的controller.rb里我有 及 为什么表单没有保存到表中?执行保存的方法不正确。这应该在create中完成 而且,您的表单看起来有误。表单数据在返回参数中的位置取决于控件的名称字段,而不是id 而不是 %input#location.form-control{:type => "Location"} 我希望看到 %input#landslide_location.form-control{:type => "text",

我这里有一张表格

在routes.rb中,我有

在你的controller.rb里我有

为什么表单没有保存到表中?

执行保存的方法不正确。这应该在create中完成

而且,您的表单看起来有误。表单数据在返回参数中的位置取决于控件的名称字段,而不是id

而不是

%input#location.form-control{:type => "Location"}
我希望看到

%input#landslide_location.form-control{:type => "text", :name => "landslide[location]"}

检查save的返回值,可能是因为您的模型经过验证。我改为您的,但仍然不起作用。我认为表单有问题。这是我的提交按钮%button.btn.btn默认值{data dismise=>modal,:type=>submit}submit。我还需要每个字段的特定属性吗?是的,你是对的,你的表单是非标准的。查看我的编辑。但它不起作用。表单在视图/索引中,这有问题吗?是的,我原以为你会遵循rails的惯例。既然你没有,所有的赌注都输光了。我不知道你的应用程序还有什么奇怪的地方。您决定不遵循标准实践有什么原因吗?
def landslide_params
  params.require(:landslide).permit(:total_id, :year_id, :start_date, :end_date, :day_number, :continent, :country, :location, :type, :admin_level, :new_lat, :new_long, :mapped, :spatial_area, :fatalities, :injuries, :notes, :sources)
end
  def new
    @landslide = Landslide.new
  end

  def create
    @landslide = Landslide.new(landslide_params)
    if @landslide.save
      render plain: @landslide.inspect
    else
      render :new
    end
  end
%input#location.form-control{:type => "Location"}
%input#landslide_location.form-control{:type => "text", :name => "landslide[location]"}