我不知道这是否可能,但我希望我的结果看起来像这样
<input id="contacts_custom_field_phone_number_28445" name="contacts[custom_field][phone_number_28445]" size="30" type="text">
所以这是我的表单模型
class Form
include ActiveModel::Validations
include ActiveModel::Conversion
include ActiveModel::Translation
extend ActiveModel::Naming
attr_accessor :config, :client, :subject, :email, :phone_number_28445,
:custom_field_company_28445, :description, :custom_field
validates_presence_of :subject, :message => '^Please enter your name'
validates_presence_of :description, :message => '^Question(s), and/or feedback can not be blank'
validates :email, presence: true
validates_format_of :email, :with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
self.config = YAML.load_file("#{Rails.root}/config/fresh_desk.yml")[Rails.env]
self.client = Freshdesk.new(config[:url], config[:api_key], config[:password])
end
def post_tickets
client.post_tickets({
:subject => "Web Inquiry From, #{subject}",
:email => email,
:custom_field => custom_field,
:phone_number_28445 => phone_number_28445,
:description => description
})
end
def persisted?
false
end
结尾
所以我有一个领域叫
:custom_field
和
:phone_number_28455
过去我只是这样做
= f.text_field :custom_field_phone_number_28445, name: 'contacts[custom_field][phone_number_28445]'
我刚刚纠正了名称值
在我的模型中,我没有在 post_tickets 方法中指定每个参数,而是将它传递给 params 的参数
def post_tickets(params)
client.post_tickets(params)
end
它奏效了
我只需要弄清楚如何让我的名称值看起来像我想要的那样,而不会在视图中覆盖它