What you want to do is called "Nested Models".
First you have to tell the model to allow the other model like this:
# app/model/user.rb
class User < ActiveRecord::Base
belongs_to :role
accepts_nested_attributes_for :role
end
the next thing is in your view
#app/views/users/new.html.ham
= simple_form_for @user do |f|
= f.input :name
= f.input :email
%br
= f.simple_fields_for :role do |role|
= role.input :designer
= role.input :developer
= f.button :submit, "Send Message", :class => 'btn btn-primary btn-block'
Now last but bot least you to be able to accept the new params in the controller
class UsersController < ApplicationController
expose(:users){User.all.order(:id)}
expose(:user, attributes: :user_params)
def new
@user = User.new
@user.role.build
end
def create
if user.save
flash[:notice] = t(:user_was_successfully_created)
redirect_to root_path
else
render :new
end
end
private
def user_params
params.require(:user).permit(
[
:email ,
:name ,
role_attributes: [
:designer,
:developer,
]
]
)
end
end
you can look at a sample app https://github.com/mzaragoza/sample_nestes_forms
I hope that this helps
Happy Hacking