如何获得Rails的字段语法以匹配HTML呈现的名称?

时间:2013-08-09 18:13:20

标签: ruby-on-rails ruby ruby-on-rails-3

我需要我的Rails代码来渲染其中一个表单字段:

contacts[:custom_field][phone_number]

我已经尝试过各种各样的方法让我的模板文件能够正常工作:

:custom_field=> :phone_number

我在HTML中得到了这个:

name="contacts[{:custom_field=>:license_1234, :class=>"text_field width_100_percent"}]"

并且ID应该看起来像

id="helpdesk_ticket_custom_field_phone_number_50754"

但是,当我提交表单时,我收到错误消息,说它无法连接到API。

 Freshdesk::ConnectionError in Website::ContactsController#create

 Connection to the server failed. Please check hostname

我在控制台中执行此操作

  contacts.post_tickets(name: "John Doe", email: 'user@exmaple.net', :custom_field=>{:phone_number=>"123-123-1234"})

它有效!和帖子,但我似乎无法在我的实际代码中复制这个

html

= form_for(:contacts, url: contacts_path) do |f|
  = f.label "Name"
  %br
  = f.text_field :subject, class: "text_field width_100_percent"
  %br
  %br    
  = f.label "Email"
  %br    
  = f.email_field :email, class: "text_field width_100_percent"
  %br
  %br
  = f.label "Phone"
  %br    
  = f.text_field :custom_field=>{:phone_number_50754=>"AMD-123"}
  %br
  %br
  = f.label "Question(s), and/or feedback"
  %br
  = f.text_area :description, class: "text_field width_100_percent"
  %br
  %br
  = f.submit "Submit", class: 'btn btn-warning'

0 个答案:

没有答案