Friday, 9 August 2013

How do I get Rails' field syntax to match HTML rendered name?

How do I get Rails' field syntax to match HTML rendered name?

I need my Rails code to render one of its form fields like this:
contacts[:custom_field][phone_number]
I've tried all sorts of things to get this to work in my template file:
:custom_field=> :phone_number
I get this in my HTML:
name="contacts[{:custom_field=>:license_1234, :class=>"text_field
width_100_percent"}]"
and the ID should look like
id="helpdesk_ticket_custom_field_phone_number_50754"
But, when I submit my form, I get an error saying it can't connect to the
API.
WHen i do this in my console
contacts.post_tickets(name: "John Doe", email: 'user@exmaple.net',
:custom_field=>{:phone_number=>"123-123-1234"})
it works! and posts but i cant seem to replicate this in my actualy code
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'

No comments:

Post a Comment