这些我都准备好了,但是当时text_field的值没有插入到数据库表中,reaming value插入成功但是有一个值没有插入。
我能理解我错在哪里以及缺少什么......
_employee_details.html.erb
<%= form_for(:employee_details, :url => {:controller => 'hr', :action => 'create'}) do |f| %>
<%= f.text_field :employee_id, { :value=> "123548", :disabled=>true , :required => true, placeholder: 'E12345678', class: 'form-control' } %>
<% end %>
hr_controller.rb
class HrController < ApplicationController
def new
@employees = EmployeeDetail.new
end
def create
@employees = EmployeeDetail.new(employee_params)
if @employees.save
redirect_to :action => 'internal_employee_page'
else
redirect_to :action => 'internal_employee_page'
end
end
private
def employee_params
params.require(:employee_details).permit(:offer_letter_id, :employee_id, :bank_ac, :bank_ifsc, :spouse_name, :gender, :work_end_date)
end
end
所有值已成功插入到 employee_details 表中接受 employee_id
employee_details.rb 这是我的模式
class EmployeeDetail < ActiveRecord::Base
belongs_to :user
validates :offer_letter_id, presence: true
end
我已经试过了,但是不行
禁用输入不会提交数据。
而不是禁用使用只读属性:
<%= f.text_field :employee_id, { :value=> "123548", :readonly => true , :required => true, placeholder: 'E12345678', class: 'form-control' } %>
<%= form_for(:employee_details, :url => {:controller => 'hr', :action => 'create'}) do |f| %>
<%= f.text_field :employee_id, { :value=> "123548", :readonly => true , :required => true, placeholder: 'E12345678', class: 'form-control' } %>
<% end %>
Here is the documentation of it
我是一名优秀的程序员,十分优秀!