これが可能かどうかはわかりませんが、結果を次のようにしたいです
<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
そしてそれは働いた
ビューで上書きせずに、名前の値を希望どおりに表示する方法を理解する必要があります