The best way to handle this is to use simple_fields_for
like so:
<%= simple_form_for @user do |f| %>
<%= f.input :first_name %>
<%= f.input :last_name %>
<%= f.input :email %>
<%= simple_fields_for :other do |o| %>
<%= o.input :change_password, as: :boolean, label: 'I want to change my password' %>
<% end %>
<% end %>
In this example, I have added a new field called change_password
which is not part of the underlying user
model.
The reason this is a good approach, is that it lets you use any of the simple form inputs / wrappers as fields. I don't care for the answer by @baxang, because it doesn't allow you to use different types of inputs. This seems more flexible.
Notice though for this to work, I had to pass :other
to simple_fields_for
. You can pass any string/symbol as long as there is not a model with that same name.
I.e. unfortunately I can't pass :user
, as simple_form would try to instantiate a User model, and we'd get the same error message again...