Devise shouldn't be modified; it's just a series of controllers and a model.
If you want to create an employee
, and then pass data through to the User
model, you've taken the right approach.
What you'll need to do is keep to convention (IE build the User
model etc) to ensure the functionality of Devise is maintained:
#app/controllers/employees_controller.rb
class EmployeesController < ApplicationController
def new
@employee = Employee.new
@employee.build_user
end
def create
@employee = Employee.new employee_params
@employee.save
end
private
def employee_params
params.require(:employee).permit(:name, user_attributes: [:email, :password, :password_confirmation])
end
end
Now, the only problem with this is that user_attributes
may be false, as Devise is famously finicky with its strong params.
--
To get the form to work, you'll be able to use the following:
#app/views/employees/new.html.erb
<%= form_for @employee do |f| %>
<%= f.text_field :name %>
<%= f.fields_for :user do |user| %>
<%= user.email_field :email %>
<%= user.password_field :password %>
<%= user.password_field :password_confirmation %>
<% end %>
<%= f.submit %>
<% end %>
I don't have any reason - or tests - to disprove this. Devise even suggests that you can load forms using the User.new
invocation. Thus, I'd surmise that the main hurdle you'll have is the passing of the strong params.