通过Rails 4中的字段创建新记录

时间:2016-07-30 16:54:28

标签: ruby-on-rails-4

我正在尝试在生产信息页面中创建新的石油生产。田地正在出现,但我无法获得石油生产。任何帮助表示赞赏

Productioninfos_controller.rb

  def index
      @productioninfos = Productioninfo.all
  end
  def new
     @productioninfo = Productioninfo.new
  end 
  def productioninfo_params
     params.require(:productioninfo).permit(:firstproduction, :lastproduction, :numberofcompl, :totaldepth, :productionzone, oilproductioninfos_attributes: [:id, :oilcum, :avgbpmlastsixmonths, :avgbpodlastsixmonths])
  end

Productioninfo.rb(model)

has_many :oilproductioninfos
accepts_nested_attributes_for :oilproductioninfo, :allow_destroy => :true,  :reject_if => :blank

Oilproductioninfo.rb(model)

belongs_to :productioninfo

Productioninfos_form.html.erb

<%= f.fields_for :oilproductioninfos do |ff| %>

  <div>
    <%= ff.label :oilcum %>
    <%= ff.text_field :oilcum %>

    <%= ff.label :avgbpmlastsixmonths %>
    <%= ff.text_field :avgbpmlastsixmonths %>

    <%= ff.label :avgbpodlastsixmonths %>
    <%= ff.text_field :avgbpodlastsixmonths %>
  </div>

0 个答案:

没有答案