gpt4 book ai didi

ruby-on-rails - ruby on rails 中没有条目保存到数据库中?

转载 作者:搜寻专家 更新时间:2023-10-30 19:41:22 24 4
gpt4 key购买 nike

我创建了一个名为 tenants 的表,其中包含以下列

class CreateTenants < ActiveRecord::Migration
def change
create_table :tenants do |t|
t.text :company_name
t.text :work_area
t.text :second_pref
t.text :third_pref
t.integer :who_are_you
t.integer :number_of_bedroom
t.text :other_specs
t.string :budget
t.string :name
t.string :email
t.string :contact_number

t.timestamps null: false
end
end
end

我正在按照以下表格将数据输入表格

        <%= form_for Tenant.new do |val| %>

<%= val.label :company_name, "Company Name" %>
<%= val.text_field :company_name, class: 'form-control' %>

<%= val.label :work_area, "Work Area" %>
<%= val.text_field :work_area, class: 'form-control' %>

<%= val.label :second_pref, "Second Preference" %>
<%= val.text_field :second_pref, class: 'form-control' %>

<%= val.label :third_pref, "Third Preference" %>
<%= val.text_field :third_pref, class: 'form-control' %>

<%= val.label :who_are_you, "Are you Family/Bachelor?" %>
<%= val.text_field :who_are_you, class: 'form-control' %>

<%= val.label :number_of_bedroom, "Number of Bedroom" %>
<%= val.text_field :number_of_bedroom, class: 'form-control' %>

<%= val.label :other_specs, "Other Requirments" %>
<%= val.text_field :other_specs, class: 'form-control' %>

<%= val.label :budget, "Your Budget" %>
<%= val.text_field :budget, class: 'form-control' %>

<%= val.label :name, "Name" %>
<%= val.text_field :name, class: 'form-control' %>

<%= val.label :email, "Email" %>
<%= val.text_field :email, class: 'form-control' %>

<%= val.label :contact_number, "Contact Number" %>
<%= val.text_field :contact_number, class: 'form-control' %>

<%= val.submit "Submit", class: "btn btn-primary" %>

<% end %>

当我填写所有必填项并单击提交时,我在 Rails 服务器日志中看到以下输出。

Started POST "/tenants" for ::1 at 2015-11-15 11:41:27 +0530
Processing by TenantsController#create as HTML
Parameters: {
"utf8"=>"✓", "authenticity_token"=>"26KYMFmofF+A1UrF+eWu21nEGbVO3n2bUSPl8340k8hY1JQhYF2kfhOHLmlF+r1Tj5UB7h6H+IJ7MY+Rx+o4CA==",
"tenant"=>
{
"company_name"=>"Housing.com",
"work_area"=>"Hiranandani Business Park",
"second_pref"=>"Chandivali",
"third_pref"=>"Vikhroli",
"who_are_you"=>"Bachelor",
"number_of_bedroom"=>"3",
"other_specs"=>"Gym, Swimming Pool",
"budget"=>"55000",
"name"=>"Shravan Kumar Gond",
"email"=>"shravan.ma.iitkgp@gmail.com",
"contact_number"=>"9475593772"
},
"commit"=>"Submit"
}
Unpermitted parameter: budget
(0.1ms) begin transaction
(0.1ms) rollback transaction

谁能告诉我,为什么会这样?

最佳答案

您的 tenants_controller.rb 文件的强参数中似乎缺少 :budget。应该是这样的。

private

def tenant_params
params.require(:tenant).permit(:company_name,
:work_area,
:second_pref,
:third_pref,
:who_are_you,
:number_of_bedroom,
:other_specs,
:budget,
:name,
:email,
:contact_number)
end

关于ruby-on-rails - ruby on rails 中没有条目保存到数据库中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33717176/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com