我创建了一个表名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
有谁能告诉我,为什么会这样?
答案 0 :(得分:3)
您的:budget
文件的强参数似乎缺少tenants_controller.rb
。它应该是这样的。
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