gpt4 book ai didi

mysql - 如何在 text_field 中设置值并将这些值存储到 Rails 中的数据库表中

转载 作者:太空宇宙 更新时间:2023-11-03 16:43:08 24 4
gpt4 key购买 nike

这些我都准备好了,但是当时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

关于mysql - 如何在 text_field 中设置值并将这些值存储到 Rails 中的数据库表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40401754/

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