Reputation: 65
I am working on configuring the apartment gem for my rails app to give users the functionality to create subdomains. I have a nested form and when attempting to access "accounts/new" I am getting the following error:
no implicit conversion of Symbol into Integer in view forms
accounts/new.html.erb
<div>
</div>
<h2>Create an Account</h2>
<%= form_for @account do |f| %>
<%= f.fields_for :owner do |o| %>
<%= form_for o, :email do %>
<%= o.text_field :email, class: 'form-control' %>
<% end %>
<%= form_for o, :password do %>
<%= o.password_field :password, class: 'form-control' %>
<% end %>
<%= form_for o, :password_confirmation do %>
<%= o.password_field :password_confirmation, class: 'form-control' %>
<% end %>
<% end %>
<%= form_for f, :subdomain do %>
<div class="input-group">
<%= f.text_field :subdomain, class: 'form-control' %>
<span class="input-group-addon">.scrumteam.com</span>
</div>
<% end %>
<%= f.submit class: 'btn btn-primary' %>
<% end %>
</div>
</div>
accounts_controller.rb
private
def account_params
params.require(:account).permit(:subdomain, :owner_attributes => [:email, :password, :password_confirmation])
end
Upvotes: 0
Views: 490
Reputation: 5977
You are nesting multiple forms into each other which is not supported in HTML:
See this question for more details: Can you nest html forms?
These form_for
lines look invalid in particular:
<%= form_for o, :field_name do %>
Here, o
is a special FormBuilder
object which should not be fed to form_for
. Try this instead:
<%= f.fields_for :owner do |o| %>
<%= o.fields_for :email do %>
Unlike form_for
, it is possible to nest fields_for
blocks.
Upvotes: 1
Reputation: 11070
Not sure if this is your route problem, but form_for
creates an actual form
tag in html. You only need (and should have) 1, the fields_for
allows you to switch the form helpers to a different object, but you don't need to call form_for
again within it. If you're just trying to group your form fields, you can just add some divs and/or labels.
Upvotes: 0