我无法理解为什么rails服务器在创建记录时忽略了参数。 我有一个控制人员。
class EmployeesController < ApplicationController
before_action :set_employee, only: [:show, :edit, :update, :destroy]
# GET /employees
# GET /employees.json
def index
@employees = Employee.all
end
# GET /employees/1
# GET /employees/1.json
def show
end
# GET /employees/new
def new
@employee = Employee.new
end
# GET /employees/1/edit
def edit
end
# POST /employees
# POST /employees.json
def create
@employee = Employee.new(employee_params)
respond_to do |format|
if @employee.save
format.html { redirect_to @employee, notice: 'Employee was successfully created.' }
format.json { render action: 'show', status: :created, location: @employee }
else
format.html { render action: 'new' }
format.json { render json: @employee.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /employees/1
# PATCH/PUT /employees/1.json
def update
respond_to do |format|
if @employee.update(employee_params)
format.html { redirect_to @employee, notice: 'Employee was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @employee.errors, status: :unprocessable_entity }
end
end
end
# DELETE /employees/1
# DELETE /employees/1.json
def destroy
@employee.destroy
respond_to do |format|
format.html { redirect_to employees_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_employee
@employee = Employee.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def employee_params
params.require(:employee).permit(:employee_category_id, :employee_number, :joining_date, :first_name, :middle_name, :last_name, :gender, :job_title, :employee_position_id, :employee_department_id, :reporting_manager_id, :employee_grade_id, :qualification, :experience_detail, :experience_year, :experience_month, :status, :status_description, :date_of_birth, :marital_status, :children_count, :father_name, :mother_name, :husband_name, :blood_group, :nationality_id, :home_address_line1, :home_address_line2, :home_city, :home_state, :home_country_id, :home_pin_code, :office_address_line1, :office_address_line2, :office_city, :office_state, :office_country_id, :office_pin_code, :office_phone1, :office_phone2, :mobile_phone, :home_phone, :email, :fax, :user_id)
end
端
app/models/employee.rb
class Employee < ActiveRecord::Base
end
所以一切都退出了。但问题是,当我想创建一个新的员工记录时,控制器拒绝加入_date属性,但我不知道为什么。这太可怕了。
我的日志说
Started POST "/employees" for 127.0.0.1 at 2014-03-30 02:20:27 +0600
Processing by EmployeesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"XxCimyEd1x3uhv5jo3HIMeF4YIXCy2yE/tGRXzdvizM=", "employee"=>{"employee_number"=>"E6", "first_name"=>"talha", "middle_name"=>"da", "last_name"=>"", "gender"=>"", "email"=>"e@fd.coml", "joining_date"=>"03/27/2014", "date_of_birth"=>"03/02/1998", "employee_department_id"=>"1", "employee_category_id"=>"1", "employee_position_id"=>"1", "employee_grade_id"=>"1", "job_title"=>"", "qualification"=>"", "experience_detail"=>"", "experience_year"=>"", "experience_month"=>"", "marital_status"=>"", "father_name"=>"", "mother_name"=>"", "blood_group"=>"", "nationality_id"=>"76"}, "commit"=>"Create Employee"}
但是在sql insert命令中我得到了
INSERT INTO `employees` (`blood_group`, `created_at`, `date_of_birth`, `email`, `employee_category_id`, `employee_department_id`, `employee_grade_id`, `employee_number`, `employee_position_id`, `experience_detail`, `father_name`, `first_name`, `gender`, `job_title`, `last_name`, `marital_status`, `middle_name`, `mother_name`, `nationality_id`, `qualification`, `status`, `updated_at`, `user_id`) VALUES ('', '2014-03-29 20:20:27', '1998-02-03', 'e@fd.coml', 1, 1, 1, 'E6', 1, '', '', 'talha', '', '', '', '', 'da', '', 76, '', 1, '2014-03-29 20:20:27', 54)
(41.5ms) COMMIT
(0.2ms) BEGIN
所以这里在sql insert查询中没有join_date.but为什么它没有插入join_date而它在参数中。
请帮助我在这一点上陷入困境。