Tolsto
Tolsto

Reputation: 1428

Rails 4: text_field helper and multidimensional params attribute

<%= text_field :foo, :bar %>

will generate

<input id="foo_bar" name="foo[bar]" type="text">

But what I actually want is

<input id="form_foo_bar" name="form[foo][bar]" type="text">

How can I achieve this?

Upvotes: 0

Views: 99

Answers (2)

Vitalyp
Vitalyp

Reputation: 1089

You can do the same with Rails form helpers:

<%= form_for :form do |form| %>
  <%= form.fields_for(:foo) do |foo| %>
    <%= foo.text_field :bar %>
  <% end %>
<% end %>

Upvotes: 1

maximus ツ
maximus ツ

Reputation: 8065

You can do,

<%= text_field :foo, :bar, :name => "form[foo][bar]" %>

not tried, but should work,

<%= text_field "", "form[foo][bar]" %>

Upvotes: 2

Related Questions